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

suggestion for geolocation sample code in the guide

Hi all,

I just spent a lot of time debugging and figuring out why my geolocation code was failing, and I wanted to post the solution here because it is such a small and simple change, but it makes a big difference, and it may help someone else.

My geolocation code was actually working wonderfully and beautifully... until it would mysteriously stop.

Long story short, my suggestion is for the Geolocation (GPS) Developer Guide page here:

https://dev.fitbit.com/build/guides/geolocation/

It would have saved me hours of confusion and debugging if this line in the example code:

geolocation.getCurrentPosition(locationSuccess, locationError);

Had been this instead:

geolocation.getCurrentPosition(locationSuccess, locationError, {timeout:60 * 1000});

Without the third parameter, the timeout defaults to *infinity*, and the locationError() callback *never* gets called. That may not seem like much of a problem, but there is a side-effect. When there is an error, it "clogs the system" if the system does not call the locationError() callback to "clear the error", and so no further calls to locationSuccess() will happen either! At that point, the geolocation system is effectively dead. Whether using getCurrentPosition() or watchPosition(), once any kind of error happens with no timeout specified, locationSuccess() will never happen again (until the app is restarted).

In my usage, the (bluetooth) connection between companion and device is frequently broken, and all it takes is one break to kill all geolocation from that point forward. Restoring the bluetooth connection does not restore geolocation functionality.

The "timeout" setting in the third parameter is technically documented here:

https://dev.fitbit.com/build/reference/device-api/geolocation/

That's good and informative, but I suspect more people are cutting and pasting code from the Guide instead of slogging through the details of the API. I searched the Fitbit Community for Developers many times and could not find any mention of this issue.

Thanks for considering it,

Gary

Best Answer
1 REPLY 1

ooof, good catch Gary. I'll get the docs updated. Thanks for sharing the fix!

Best Answer
0 Votes