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.圆圈,并保留了其余部分。这一切似乎都很好!