So I have a pretty simple bit of JS using the navigator.geolocation.getCurrentPosition jammy.
$(document).ready(function(){
$(\"#business-locate, #people-l
As of mid 2020, none of the answers here provides any explanation, just hacking or guessing.
As @Coderer points out before me, secure context (https) is required today, so on more and more devices geolocation doesn't work at all with plain http:
Secure context This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The third parameter of getCurrentPosition()
(and watchPosition()
which is more suitable here) is PositionOptions object consisting of these properties:
enableHighAccurancy
(default false): if set to true, response is slower and more accurate. If you got timeout errors, keep this to false. If the accurancy is low, set it to true. In my tests 1s delay with 1-2 meters precision and there was no difference between true and false on UMAX tablet. I tested also on older iPhone with 5 meters oscilation if set to false. You can also measure accurancy in GeolocationCoordinates.accurancy property and decide dynamically.timeout
(default infinity): milliseconds before the API gives up and calls the error handler (the second parameter). Today, 5s (5000) is reasonable and in some cases 10s can make sense. Useful if you want to have plan B when geolocation sensor data is not available.maximumAge
(default 0): milliseconds when cached value is valid, the device may decide to use valid cached data instead of sensor measure. Set this to Infinity on static locations, keep at 0 otherwise.As @YoLoCo points out before me, getCurrentPosition()
and watchPosition()
interferes and I confirm his results in 2020. Generally, use watchPosition instead of getCurrentPosition periodical calls.