Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Location API using Fitbit Simulator (Mac)

ANSWERED

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

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
0 Votes
15 REPLIES 15

The simulator should return a fixed location.

Have you enabled the location permission in your package.json?

Best Answer
0 Votes

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 Answer
0 Votes

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 Smiley Very Happy )

Best Answer
0 Votes

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).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Try deleting the app from your device and reinstall it. The location permission might not have updated.

Best Answer
0 Votes

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 Answer
0 Votes

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
0 Votes

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 Answer
0 Votes

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 Answer
0 Votes

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 Answer
0 Votes

None of any callbacks is firing for me. Could you please share a snippet of working code?

Best Answer
0 Votes

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 Answer
0 Votes

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 Answer
0 Votes

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.

Best Answer

Thanks for the hint - didn't work with my devices by now 😞

 

Regards

Capitano

Best Answer
0 Votes