HTML5 Geolocation ignores enableHighAccuracy?

I am currently writing a webapp that may suffer from mobile devices. At some point, I need to get the location of the user, which I am doing with HTML5 getCurrentPosition (). I would prefer a rough fix as quickly as possible, so I call this function with the enableHighAccuracy parameter set to false.

In most cases, this works as expected; however, on some Android devices, browsers seem to ignore this attribute and always try to find the GPS location (the GPS icon appears in the notification bar). The funny thing is that this happens even if I manually turn off the GPS location in the settings.

This does not seem to be browser dependent, I tested the same code with Chrome, Firefox and Opera, and happens with simple code, for example:

<!doctype html> <html> <head> <script type="text/javascript"> function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(onLocationReceived, onLocationError, {timeout: 5000, enableHighAccuracy: false}); } else alert("Geoloc not supported by your browser"); } function onLocationReceived(position) { alert("Location retreived! " + position.coords.latitude + ", " + position.coords.longitude + " (" + position.coords.accuracy + ")"); } function onLocationError(error) { alert("Received an error! " + error.message + "(" + error.code + ")"); } </script> </head> <body> <button onclick="getLocation();">Get location</button> </body> 

So far, this has been happening on HTC One and Xiaomi 1S. Have you ever encountered this problem? Maybe this is a known mistake?

Thanks.

+4
source share
1 answer

Yes, I experience the same thing on Android Lollipop and Chrome 43. I was hoping I could getCurrentPosition without highAccuracy and at the same time run watchPosition with highAccuracy enabled.

But no. Both calls return at the same (later) time with the same (GPS) results ...

https://bugzilla.mozilla.org/show_bug.cgi?id=1057076

http://www.hyam.net/blog/archives/1432

0
source

Source: https://habr.com/ru/post/1492889/


All Articles