0

I'm making this page where you start time, your geolocation is being calculated and gets saved to a database. Whenever you stop the time, your geolocation is being recalculated and gets saved as well.

This works fine on a desktop computer where (don't ask me why) geolocation onstart differs from the geolocation onstop.

However when I visit the page on my cell phone, the geolocation is calculated correctly onstart but is then not recalculated onstop i.e. the geolocation remains the same despite not being in the same place anymore at all. Has anyone got a clue how you can force a device to recalculate the geolocation?

Thanks

Mats Raemen
  • 1,781
  • 1
  • 28
  • 41
  • Check this out, it hass all that you need - http://stackoverflow.com/questions/6181704/good-way-of-getting-the-users-location-in-android – g00dy Aug 05 '13 at 11:54
  • I wrongly tagged android in this. It's just plain html and javascript, not android code I'm looking for. – Mats Raemen Aug 05 '13 at 12:03

1 Answers1

0
navigator.geolocation.getCurrentPosition(success, error, { maximumAge : ... });

maximumAge

A positive number indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device must return a cached position regardless of its age.

https://developer.mozilla.org/en-US/docs/Web/API/window.navigator.geolocation.getCurrentPosition#PositionOptions

Try not to be too aggressive with this setting, constantly recalculating the location drains battery like no man's business.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • This seemed like a good solution, however it doesn't seem to work on my cell phone. It keeps on giving me the exact same location – Mats Raemen Aug 05 '13 at 12:59
  • Ultimately it's still up to the phone to give you the data. If it decides that an older cached location is still good enough, there's nothing you can do about it. Have you tried the other options as well, like trying to request a high accuracy location? – deceze Aug 05 '13 at 13:01
  • Yes I tried that as well, but nothing seems to help. Thanks anyways – Mats Raemen Aug 06 '13 at 10:06