Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在传单中重置地图定位器_Javascript_Leaflet_Location_Reset - Fatal编程技术网

Javascript 如何在传单中重置地图定位器

Javascript 如何在传单中重置地图定位器,javascript,leaflet,location,reset,Javascript,Leaflet,Location,Reset,我的地图定位器工作,但我不知道如何重置标记,以便在用户地理定位时重置位置。目前,我的代码如下所示: //map locator map.locate({setView: true, maxZoom: 16}); function onLocationFound(e) { var radius = e.accuracy; L.marker(e.latlng).addTo(map) .bindPopup("Vous êtes ici&q

我的地图定位器工作,但我不知道如何重置标记,以便在用户地理定位时重置位置。目前,我的代码如下所示:

    //map locator 
    map.locate({setView: true, maxZoom: 16});

    function onLocationFound(e) {
    var radius = e.accuracy;

    L.marker(e.latlng).addTo(map)
    .bindPopup("Vous êtes ici").openPopup();

    L.circle(e.latlng, radius).addTo(map);
    }

    map.on('locationfound', onLocationFound);


    function onLocationError(e) {
    alert(e.message);
    }

    map.on('locationerror', onLocationError);
    // end of geolocator with marker

覆盖板条和半径:

var marker = null;
var circle = null;

//map locator 
map.locate({setView: true, maxZoom: 16});

function onLocationFound(e) {
    var radius = e.accuracy;

    if(!marker){
        marker = L.marker(e.latlng).addTo(map);
        circle = L.circle(e.latlng,radius).addTo(map);
    }else{
        marker.setLatLng(e.latlng);
        circle.setLatLng(e.latlng);
        circle.setRadius(radius);
    }

    marker.bindPopup("Vous êtes ici").openPopup();
}

谢谢我用你给出的代码替换了L.标记和L.圆圈,并保留了其余部分。这一切似乎都很好!