Geolocation coordinates refresh?

In a perspective session running on mobile, I’m trying to display the GPS coordinates (binding a label to the corresponding session.props.geolocation.data.* property) and update them in real time as the phone moves. I’m not able to get them to change or refresh, even if I move several hundred meters (yes I’m using 10 digits after the decimal comma, so I should definitely see it changing, in the same way I see my current location in google maps move). It seems that data.timestamp isn’t updated either. Is the geolocation data found in the session properties supposed to refresh automatically, or how do I do that?

It should update automatically once you’ve started moving. Have you set geolocation.enabled to true and accepted permissions to use location on device?

Yes, I basically copied the whole thing from the ignition 8 demo server. A toggle to enable geolocation (bidirectionally bound to session.props.geolocation.enabled) and four labels bound to session.props.geolocation.data.longitude, session.props.geolocation.data.latitude, session.props.geolocation.data.altitude and session.props.geolocation.data.timestamp (with more decimals shown instead of the 2 used in the demo app). No label is updating after I enable geolocation with the toggle (and yes, of course I’ve given permissions to the ignition app to access location data). I have noticed, though, that if I toggle geolocation off then back on again, the data.timestamp value does update (but not the coordinates). Will keep experimenting.

[update]: same thing on two different phones, different brands. Both phones work just fine with google maps.

[update 2]: testing with even more phones, it looks that in some models the coordinates can be refreshed by turning geolocation off then on. If that’s the only way to do it, it’s probably worth documenting.

This still seems to be an issue. Even when using the trick of disabling + reenabling geolocation before reading the coordinates, they are still not updated. This is basically my code:

          # session event handler on always-visible perspective component, 
          # triggered by a request coming from a gateway timer script
	  session.props.geolocation.enabled = False
          session.props.geolocation.enabled = True
	
	  latitude = session.props.geolocation.data.latitude
	  longitude = session.props.geolocation.data.longitude
	  altitude = session.props.geolocation.data.altitude
	  
	  payload = {
	    'latitude': latitude,
	    'longitude': longitude,
	    'altitude': altitude
          }
	  
          # send data to gw using system.util.sendMessage()

I’ve logged the variable values after reading the coordinates, and basically they’re always the same values. Do I have to sleep a bit between geolocation enabling/disabling (would be bad though)? Or am I doing something else wrong?

So after more experimenting, coordinates seem to refresh if I use the following algorithm:

session.custom.period = 0

...
# upon request of coordinates
if session.custom.period % 2 == 0:
  # read and send coordinates
  ...
  session.props.geolocation.enabled = False
else:
  session.props.geolocation.enabled = True

session.custom.period += 1

If the coordinate requests are emitted every N seconds from the gateway, the above results in one coordinate reading every 2N seconds, and values do seem to change this way.
Looks to me that I’m still missing something (or ignition’s implementation of geolocation isn’t optimal, cannot tell).

That shouldn’t be necessary to get the coordinates to update. We just added the ability to change the GPS accuracy. I’d try changing geolocation.options.accuracy to max and see if that has any effect on the rate you receive coordinates.

Sorry to reopen this old thread, but we’re currently testing the GPS functionality and we’re seeing some issues. By far the biggest one is that coordinates are refreshed only when the screen is turned on; when it is off (which means, 99,999% of the time in our scenario) coordinates are not refreshing. This is android 8.1.0 on a MI 8 phone. The phone has already all battery optimizations/background data usage limitations I could find removed, but the problem persists. I’ve found some notes on the android development site about background location limits (https://developer.android.com/about/versions/oreo/background-location-limits). I’m not an android expert and I can’t really tell whether it’s something that should be done at the application level (like adding a foreground service) or it’s some other setting to set on the phone. Or perhaps there are helper apps that can help keep the GPS alive? I’m looking for any advice/guidance on how to proceed.
Thanks

Unfortunately you won’t be able to do anything on your side. When you turn the screen off there is no way to guarantee that the Perspective App will continue to run or communicate with the gateway. Android and iOS can kill our app or network connections in this state to preserver battery life. We do have the ability to receive GPS coords in the background, but we’d have to come up with a mechanism for sending the coords back to the gateway (perspective project) when we aren’t connected. How close to real time do you need your GPS coords?

It’s not much a matter of real time but of number of updates per unit of time. Ideally we’d like to have two datapoints per minute (ie every 30 seconds), although I suppose this requirement could be relaxed a bit and we could get down to one point every 2/3 minutes.
To me it looks like android is not killing the app (at least in our case it shouldn’t, as there will be no other user app running on the phone), it only stops the coordinate refresh and the phone starts sending stale coordinates (they’re all the same up to the last decimal digit, so it’s clearly not updating - and the device is moving meanwhile). Would the foreground service method described in the android article be a viable feature request? It could of course be made an opt-in feature, as not everyone might want it.
Thanks

Any news on this issue? A big project depends on the feasibility of this feature. Thanks

If this helps, after a lot of messing around we found this little app: https://play.google.com/store/apps/details?id=org.bruxo.gpsconnected that, together with the old trick of turning off and on the GPS periodically using the code described here Geolocation coordinates refresh? seems to somehow get the coordinates to refresh.
Of course this is a gross workaround, because we suspect that turning the GPS on and off repeatedly loses precision and now we depend on the operator always running GPS connected before launching the perspective app and not accidentally turning it off etc.
I don’t know how GPS connected does its magic, but would it be possible to integrate (as an opt-in) a similar behavior into the perspective client app?

I know this is an old thread, but I am having the same problem. I had to create a button that enabled and disabled the session.props.geolocation.enabled property in order to be able to get my GPS coordinates to update regularly. I set the GPS accuracy to the highest setting. The accelerometer data updates regularly, but not the GPS data. I tried this on several different phones. Is re-enableing the geolocation the only way to have the GPS location refresh?