# Geolocation coordinates refresh?

**URL:** <https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167>\
**Category:** Ignition Early Access\
**Created:** [March 8, 2019, 4:47pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167 "2019-03-08T16:47:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [March 8, 2019, 4:47pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/1 "2019-03-08T16:47:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mrojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrojas/32/6394_2.png) [@mrojas](https://forum.inductiveautomation.com/u/mrojas)\
**Post date:** [March 9, 2019, 12:22am UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/2 "2019-03-09T00:22:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [March 9, 2019, 9:30am UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/3 "2019-03-09T09:30:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [March 20, 2019, 2:31pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/4 "2019-03-20T14:31:39Z")

</div>

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:

```auto
          # 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?

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [March 21, 2019, 3:16pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/5 "2019-03-21T15:16:26Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![mrojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrojas/32/6394_2.png) [@mrojas](https://forum.inductiveautomation.com/u/mrojas)\
**Post date:** [March 25, 2019, 6:00pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/6 "2019-03-25T18:00:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [February 20, 2020, 1:35pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/7 "2020-02-20T13:35:59Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![mrojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrojas/32/6394_2.png) [@mrojas](https://forum.inductiveautomation.com/u/mrojas)\
**Post date:** [February 21, 2020, 8:27pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/8 "2020-02-21T20:27:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [February 21, 2020, 9:46pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/9 "2020-02-21T21:46:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [February 27, 2020, 6:00pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/10 "2020-02-27T18:00:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [March 2, 2020, 8:01pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/11 "2020-03-02T20:01:26Z")

</div>

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](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?](http://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/5?u=waldner) _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?

---

<div class="post-metadata">

**Author:** ![philkmil](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@philkmil](https://forum.inductiveautomation.com/u/philkmil)\
**Post date:** [September 23, 2021, 3:40pm UTC](https://forum.inductiveautomation.com/t/geolocation-coordinates-refresh/23167/12 "2021-09-23T15:40:13Z")

</div>

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?
