I'm using leaflet 1.0.3 with latest plugin leaflet-locatecontrol. When I start to locate myself, it takes arround 5 seconds. My position is being watched constantly and even if I move right after the last position update it takes 5 seconds again to reposition my map. I've tried using parameters such as timeout or maximumAge, but these have no effect. I've searched for any numbers in leaflet.js to replace these with lower values, but that didn't help either.

A position update interval of 500ms would be awesome for my application. From what I've read, Leaflet uses Browser API to process geolocations. But I managed to locate myself in OpenLayers with my desired update interval. Is there any way to hack Leaflet's update Interval?

var lc = L.control.locate({
        position: 'topright',
        strings: {
            enableHighAccuracy: true, 
            setView: true,              //no effect
            keepCurrentZoomLevel: true, //no effect
            watch:false,                //no effect
            timeout: 1000,              //no effect
            maximumAge: 1000            //no effect


1 Answer 1


Leaflet relies on the browser's Geolocation.watchPosition and other bits of the Geolocation API. The code for L.Map.locate does not add any extra timeouts or delays.

Let me quote from the specs of the Geolocation API, emphasis mine:

In step 5.2.2 of the watch process, the successCallback is only invoked when a new position is obtained and this position differs significantly from the previously reported position. The definition of what constitutes a significant difference is left to the implementation. Furthermore, in steps 5.2.2 and 5.2.3, implementations may impose limitations on the frequency of callbacks so as to avoid inadvertently consuming a disproportionate amount of resources.

In other words: the web browser limits the rate at which it provides location updates (to Leaflet, or to your own code if you use the Geolocation API directly). And there's nothing you can do about it (unless you are willing to create your own web browser).

  • what if i would use getCurrentPosition instead of watchPosition in an setInterval function and by doing so force a location update?
    – Revo
    Jun 23, 2017 at 11:57
  • also: is there any other free-to-use api which allows a higher frequency and doesn't rely on browser api?
    – Revo
    Jun 23, 2017 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.