Leaflet watch active duplicating marker issue WILLING TO PAY

51 views
Skip to first unread message

UK Weather Forecast

unread,
May 3, 2016, 4:40:39 AM5/3/16
to Leaflet
Hello

On our weather radars I'm using geo location to add the users location to the map, it updates and gets their new location pretty much real time. The issue I have is it seems to plot a new circle marker on each location update. I don't want this, I want it to remove the old circle marker and plot the new one as they go along.


This is my current code


map.locate({setView: true, watch: true, enableHighAccuracy: true, maximumAge: 10, timeout: 3000000, maxZoom: 13 });
function onLocationFound(e) {
    var radius = e.accuracy / 29;

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

map.on('locationfound', onLocationFound);

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

map.on('locationerror', onLocationError);

}


I would appreciate it if anyone could help me and I would be more than happy to make a donation to anyone that can give me the correct code to sort this problem out.


Thanks

Lewis 


Claudio Schilling

unread,
May 6, 2016, 10:09:36 AM5/6/16
to leafl...@googlegroups.com
Perhaps the easiest way to accomplish that would be removing the L.circle() instantiation from the onLocationFound() function and placing it on the same scope where "map" is located, you'd just have to keep a reference to the instantiated circle object and then inside onLocationFound() you would just call setLatLng() and setRadius() on the same existing circle object to update its position and radius instead of creating a new one each time onLocationFound() is called.

Claudio


--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages