10-22-2017 18:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-22-2017 18:58
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am having two issues while I am trying to capture the device location and use it in my app.
1. See code below. It is a simple app to track GPS data, that I will then use to do other stuff. When I test it, the app runs for 30sec to few minutes, showing the location info. Then crashes (goes back to app selection screens).
I don't seem to understand what could be wrong with the code to create the watch to close the app. Any hints?
2. If I use watchPosition, as described from the example in the guide, I do not get any position reading at all, nor error messages. Is there something wrong with the guide's code, or am I supposed to add something else?
Thanks
import document from "document"; import { geolocation } from "geolocation"; import { display } from "display"; display.autoOff = false; let gpsStatus = document.getElementById("gps-status"); let gpsLat = document.getElementById("gps-lat"); let gpsLon = document.getElementById("gps-lon"); let gpsHeading = document.getElementById("gps-heading"); let gpsSpeed = document.getElementById("gps-speed"); function refreshData() { geolocation.getCurrentPosition(locationSuccess, locationError); function locationSuccess(position) { console.log("GPS on"); gpsStatus.innerText = "GPS on" ; // gpsLat.innerText = position.coords.latitude; // gpsLon.innerText = position.coords.longitude; // gpsHeading.innerText = position.coords.heading; gpsSpeed.innerText = Math.round(position.coords.speed*3.6) + " KMH"; } function locationError(error) { console.log("Error: " + error.code, "Message: " + error.message); // gpsLat.style.fill = "red"; gpsLat.innerText = "Connecting GPS"; } } refreshData(); setInterval(refreshData, 1000);

10-23-2017 00:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-23-2017 00:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm only a journeyman javascript coder, and I haven't had any experience with the Ionic, but.... I see your success and fail functions located inside the refreshData function, whilst I would have expected to see them outside the refreshData function.

10-23-2017 05:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-23-2017 05:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If I don't put them inside the refreshData(), how does it refresh my location and calculate speed and distance?

10-23-2017 09:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-23-2017 09:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@agsurf5 wrote:
If I don't put them inside the refreshData(), how does it refresh my location and calculate speed and distance?
They are the callback functions for getCurrentPosition().
You call refreshData(), that calls getCurrentPosition(). If that is successful, it will call locationSuccess().

10-23-2017 18:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-23-2017 18:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hey @JonFitbit I changed it, but it still crashes every time. 30 seconds or so, and it closes.
It is pretty simple, just displaying speed. I am testing to see if I can move ahead in calculating more, but it is really not stable. Any advice?
Ps thanks for the continuous help.
Here is the code:
import document from "document"; import { geolocation } from "geolocation"; import { display } from "display"; display.autoOff = false; let gpsStatus = document.getElementById("gps-status"); let gpsLat = document.getElementById("gps-lat"); let gpsLon = document.getElementById("gps-lon"); let gpsHeading = document.getElementById("gps-heading"); let gpsSpeed = document.getElementById("gps-speed"); function refreshData() { geolocation.getCurrentPosition(locationSuccess, locationError); } function locationSuccess(position) { console.log("GPS on"); gpsStatus.innerText = "GPS on" ; // gpsLat.innerText = position.coords.latitude; // gpsLon.innerText = position.coords.longitude; // gpsHeading.innerText = position.coords.heading; gpsSpeed.innerText = Math.round(position.coords.speed*3.6) + " KMH"; } function locationError(error) { console.log("Error: " + error.code, "Message: " + error.message); // gpsLat.style.fill = "red"; gpsStatus.innerText = "Connecting GPS"; } refreshData(); setInterval(refreshData, 1000);

10-24-2017 13:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-24-2017 13:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I would try reducing it to bare minimum, does it still crash?
Just console.log("success") or console.log("failure")
Then slowly add back code to see where it's failing.
You could also try coding a bit more defensively.
if (position && position.coords && position.coords.speed) {
gpsSpeed.innerText = Math.round(position.coords.speed*3.6) + " KMH";
}

10-24-2017 15:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-24-2017 15:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I Don't understand, Jon
@JonFitbit wrote:I would try reducing it to bare minimum, does it still crash?
Just console.log("success") or console.log("failure")
Then slowly add back code to see where it's failing.
You could also try coding a bit more defensively.
if (position && position.coords && position.coords.speed) {
gpsSpeed.innerText = Math.round(position.coords.speed*3.6) + " KMH";
}
. If it's broken, why are you encouraging him to test it further?

10-24-2017 16:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-24-2017 16:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@raceQs wrote:
I Don't understand, Jon
. If it's broken, why are you encouraging him to test it further?
watchPosition() isn't working, but it doesn't crash. I think his issue lies elsewhere.

10-25-2017 13:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-25-2017 13:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I am not using watchPosition (as it doesn't work), but getCurrentPosition.
I took everything off from screen, I just have the text that show "connecting GPS" and then "GPS on".
No variables, nor numbers moving. It is on for a minute max, then it closes.
1. Are you at fitibit using the same functionality for activities? It doesn't seem to crash when using exercises, but I'll make sure to test it again later just in case I have a problem with my own device. Same code/implementation as from the guide?
2. Did anybody successfully implemented geolocation in an app so far?
11-01-2017 04:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-01-2017 04:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Bumping this up as I am completely stuck in developing my app, if I can't get Geolocation to work.
Did anybody successfully implemented it in an app so far? Mine keep on crashing every minute or so.

11-11-2017 12:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-11-2017 12:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
After the installation of the last OS update my app with geolocation is working.
I'm calling geolocation.getCurrentPosition () every second and normaly I use my app for 30 minutes.
Capitano

11-11-2017 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-11-2017 18:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm calling geolocation.getCurrentPosition () every second and normaly I use my app for 30 minutes.
Glad it's working for you. I'd recommend optimizing so you're not excessively draining the battery if you don't need to.

11-11-2017 20:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-11-2017 20:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Works for me as well. I will help with optimizing the code, but I am on it as of now. Thanks guys

11-12-2017 12:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-12-2017 12:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@JonFitbit wrote:I'm calling geolocation.getCurrentPosition () every second and normaly I use my app for 30 minutes.
Glad it's working for you. I'd recommend optimizing so you're not excessively draining the battery if you don't need to.
Thank you for your hint.
I want to summarize the distance I run during an exercise. So I guess I have to call the gps-function that way. I could use a longer interval but that reduces the accuracy...
Do you have another suggestion @JonFitbit?
Capitano

11-14-2017 13:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-14-2017 13:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Capitano it's just a trade off between the accuracy you need for your app, and the impact that has on battery.

11-25-2017 02:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-25-2017 02:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi all,
do you have problems with geolocation since the last update (OS 27.30.5.16)?
Or do your apps still run without problems?
My app resets the ionic since using it.... 😞
https://community.fitbit.com/t5/SDK-Development/GPS-failure-back-again/m-p/2315221#M1660
Capitano

