Can I see the location in the background on the mobile (iOS / Android)?

With a watch, I mean using HTML5 support based on the native Geolocation. This is for the web application, not for it. Thanks for the help: D

+7
javascript html5 geolocation
source share
3 answers

You cannot view the user's location from a web application in the background. I tested it on Chrome (Android M), and as soon as the web application goes into the background, the GPS icon disappears and the clock position process stops. (As soon as the web application reappears in the foreground, the browsing process will resume).

The same thing happens when the device is locked. The browsing process stops until the user unlocks it, and the web application is in the foreground.

+9
source share

I tested the watchPosition api on android, it seems to work for firefox, but not chrome.

UPDATE: - I am using Nexus 5X, with Android N

0
source share

Yes. You can definitely see the location in the background if your mobile browser supports the Geolocation API .

You can use the watchPosition() function.

watchPosition () Code snippet

 var watchID = navigator.geolocation.watchPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); 

If the position data changes (either by movement of the device, or a lot of accurate geo-information), you can set up a callback function that is called with updated location information. Done using the watchPosition() function, which has the same input getCurrentPosition() parameters. The callback function is called several times, allowing the browser to either update your location, or you navigate or provide a more accurate location.

getCurrentPosition () Code snippet

 navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); 

For more information, contact Mozilla / Geolocation / WatchCurrentPosition

Hope this helps!

-one
source share

All Articles