Hi guys -
I am trying to build a super simple app that just displays my long/lat coordinates when using the app. The following is a very simple piece of code pulling directly from the Geolocation API, but when I run the app, it is returning "undefined".
import document from "document";
import { geolocation } from "geolocation";
let demotext = document.getElementById("demotext");
demotext.text = geolocation.getCurrentPosition(locationSuccess, locationError);
function locationSuccess(position) {
console.log("Latitude: " + position.coords.latitude,
"Longitude: " + position.coords.longitude);
}
function locationError(error) {
console.log("Error: " + error.code,
"Message: " + error.message);
Could it be an issue of using the simulator? I haven't been able to test using my actual Versa device.
Thanks
Pepe
Answered! Go to the Best Answer.
Best Answer
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.
Oh dear, I just saw the problem... "Versa".
Sorry, but Versa doesn't have GPS, hence the zero values. I should have spotted that in your first post.
You'll need to use the companion to get GPS data instead.
Best Answer
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.
Hi Jon - thank you for your response. I have enabled the the location permission in the package.json file, but I am not getting a response from the simulator. When I run the following code, it simply prints "undefined" to the console until it times out. Interestingly, when I run this chunk of code using navigator.geolocation on my Chrome browser, it prints "undefined" for a couple seconds and then returns my lat/long.
import document from "document";
import { geolocation } from "geolocation";
var options = { enableHighAccuracy: false, timeout: 15000, maximumAge: 0 };
document.getElementById("latitude").text = "Searching...";
console.log("output :" + geolocation.getCurrentPosition(locationSuccess, locationError, options));
function locationSuccess(position) {
console.log("In success function...");
console.log("Latitude: " + position.coords.latitude,
"Longitude: " + position.coords.longitude);
document.getElementById("latitude").text = "Latitude: " + position.coords.latitude;
document.getElementById("longitude").text = "Longitude: " + position.coords.longitude
}
function locationError(error) {
console.log("In error function...");
console.log("Error: " + error.code,
"Message: " + error.message);
document.getElementById("latitude").text = "Error code: " + error.code
document.getElementById("longitude").text = error.message
}In the documentation, I read that the Device API and Companion API both have identical implementations of the GPS API. Does it matter which one I am using?
Best AnswerUpdate:
When I run the code on my Versa device outside, I get "undefined" for a few seconds until I get the following response every time:
Latitude: 0
Longitude: 0
1. Why would the simulator time out?
2. Is there an issue that might be causing the API to return (0, 0) as my coordinates? ( Note: I am definitely not in the middle of the ocean at 0,0
)
Best AnswerI know it's not the main issue, but the 'undefined's could be because the GPS hasn't locked on yet. You'd need to test for this condition and handle it nicely (eg, a pretty 'waiting' indicator).
Best Answer
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.
Try deleting the app from your device and reinstall it. The location permission might not have updated.
Best AnswerThanks for the suggestion @JonFitbit
I reinstalled the app, making sure the location permission was enabled, but this doesn't seem to be the issue. I am still getting lat=0, long=0 whenever I fire up the app outdoors.
It's strange because it technically is returning a value and going to my "success" function - the value just happens to be (0, 0).
Has anyone else run into this issue before? FYI - I am running this on a Fitbit Versa (v 32.4.19)
Best Answer
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.
Oh dear, I just saw the problem... "Versa".
Sorry, but Versa doesn't have GPS, hence the zero values. I should have spotted that in your first post.
You'll need to use the companion to get GPS data instead.
Best AnswerThanks @JonFitbit! I had a inkling that was the issue... but that makes a lot of sense to me.
Are there any resources to get me up and running with the Companion API? I am fairly new to JS and Fitbit dev.
Best Answer
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.
The BART example shows getting data with a companion:
https://github.com/Fitbit/sdk-bart
Probably take a look at the Companion and Messaging guides too https://dev.fitbit.com/build/guides/
Best AnswerI took a look at these and they were very helpful. I finally got the app running the way I want it to.
Thanks @JonFitbit!
Best AnswerHi,
I'm also trying in getting the location on the Versa. I observe three things:
- choosing one of the training options with GPS on will show speed from GPS after 10 seconds, and Handy will report GPS link active notification. So basically everything works.
- using the geolocation API on the device will also show the GPS link active notification on the Handy, and will start transmitting all "0" after 10 seconds
- using the geolocation API on the companion will not work at all (only returning timeout error).
@JonFitbitIs there any working APP for the Versa using the handy GPS ? Could you post some snippets, or better, some runnable example app ?
Best,
Ingo.
Best AnswerHi @peperez,
I also have an issue with the companion GPS on the Versa.
Can you show some example code or how you changed your example above to make it work?
Thanks in advance
Capitano
Best AnswerHi,
I had success not in changing the code, but re-starting the mobile phone, restarting the clock, and syncing the fitbit app with the Versa. Then it usually works. Sometimes the communication channel just doesn't transmit anything or stops transmitting, then the above measures will help.
Best,
Ingo.