10-17-2019 09:38
10-17-2019 09:38
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
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
10-21-2019 01:38
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;
}
Best Answer