04-23-2018 12:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-23-2018 12:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

Accepted Solutions
04-25-2018 06:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-25-2018 06:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

04-24-2018 09:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-24-2018 09:04
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The simulator should return a fixed location.
Have you enabled the location permission in your package.json?

04-24-2018 10:45 - edited 04-24-2018 11:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-24-2018 10:45 - edited 04-24-2018 11:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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?

04-24-2018 12:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-24-2018 12:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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 )

04-24-2018 13:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-24-2018 13:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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).
Gondwana Software

04-25-2018 02:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-25-2018 02:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Try deleting the app from your device and reinstall it. The location permission might not have updated.

04-25-2018 06:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-25-2018 06:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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)

04-25-2018 06:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-25-2018 06:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

04-25-2018 07:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-25-2018 07:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

04-25-2018 12:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-25-2018 12:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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/

04-25-2018 15:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-25-2018 15:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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!

05-02-2018 10:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-02-2018 10:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
None of any callbacks is firing for me. Could you please share a snippet of working code?

08-26-2018 10:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-26-2018 10:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

11-01-2018 11:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-01-2018 11:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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

11-01-2018 16:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-01-2018 16:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-02-2018 01:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for the hint - didn't work with my devices by now 😞
Regards
Capitano

