I Update the position of the marker through the localization function.

However, the user might wish to zoom to a differed level, but when the position maker gets updated the map always zooms back to the value set in the locate maxZoom option.

Is there a way to change the maxZoom value dynamically depending on the zoom level the user has chosen?

var gpsMarker = null;
    var gpsCircleMarker;

    function onLocationFound(e) {
        var radius = e.accuracy / 2;
        var popupContent = "You are within " + radius + " meters from this point";

    if (gpsMarker == null) {
        gpsMarker = L.marker(e.latlng, {icon: IsyUserIcon}).addTo(map);
        gpsCircleMarker = L.circle(e.latlng, radius).addTo(map);
    else {

map.on('locationfound', onLocationFound);

map.locate({setView: true, watch: true, maxZoom: 16});
  • 1
    How can you expect somebody will answer your question if you don't even bother to comment, much less upvote or accept the answer to your previous question gis.stackexchange.com/questions/342071/…, the result of which you are obviously using.
    – TomazicM
    Nov 18, 2019 at 7:27
  • I have exactly the same issue, I need something like this js map.locate({setView: true, watch: true, minZoom:14, maxZoom: 16}); So if the current zoom level is 14, 15 or 16 it should stay the same, even in case of onLocatonFound event. Currently behavior is, the zoom level is always set to maxZoom (in this case 16) onLocationFound event which is quite annoying.
    – Marko
    Oct 31, 2023 at 15:38


Your Answer

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

Browse other questions tagged or ask your own question.