04-23-2018 12:49
04-23-2018 12:49
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 Answer04-25-2018 06:39
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.
04-25-2018 06:39
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 Answer04-24-2018 09:04
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.
04-24-2018 09:04
The simulator should return a fixed location.
Have you enabled the location permission in your package.json?
Best Answer04-24-2018 10:45 - edited 04-24-2018 11:06
04-24-2018 10:45 - edited 04-24-2018 11:06
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 Answer04-24-2018 12:28
04-24-2018 12:28
Update:
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 Answer04-24-2018 13:37
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
04-24-2018 13:37
I 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 Answer04-25-2018 02:46
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.
04-25-2018 02:46
Try deleting the app from your device and reinstall it. The location permission might not have updated.
Best Answer04-25-2018 06:31
04-25-2018 06:31
Thanks 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 Answer04-25-2018 06:39
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.
04-25-2018 06:39
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 Answer04-25-2018 07:11
04-25-2018 07:11
Thanks @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 Answer04-25-2018 12:29
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.
04-25-2018 12:29
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 Answer04-25-2018 15:07
04-25-2018 15:07
I 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 Answer05-02-2018 10:45
05-02-2018 10:45
None of any callbacks is firing for me. Could you please share a snippet of working code?
Best Answer08-26-2018 10:26
08-26-2018 10:26
Hi,
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 Answer11-01-2018 11:44
11-01-2018 11:44
Hi @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 Answer11-01-2018 16:28
11-01-2018 16:28
Hi,
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.
11-02-2018 01:50
11-02-2018 01:50
Thanks for the hint - didn't work with my devices by now 😞
Regards
Capitano
Best Answer