10-17-2019 09:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-17-2019 09:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Newbie here, I'm trying to get the location of a device and use the coords to make other API calls.
I've been unable to use the coords outside of the locationSuccess function. Is there a way to get around this, has anyone succeeded with this?
10-21-2019 01:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-21-2019 01:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You can define a function which accepts lat/lon and call that function within locationSuccess, or you can define some variables outside the scope of locationSuccess and set them within locationSuccess.
function doSomethingWithLocation(lat, lon) {
console.log(`Do something: ${lat} || ${lon}`)
}
function locationSuccess(position) {
console.log("Latitude: " + position.coords.latitude,
"Longitude: " + position.coords.longitude);
doSomethingWithLocation(position.coords.latitude, position.coords.longitude)
}
// OR
var myLat, myLon;
function locationSuccess(position) {
console.log("Latitude: " + position.coords.latitude,
"Longitude: " + position.coords.longitude);
myLat = position.coords.latitude;
myLon = position.coords.longitude;
}

