[GIS] Update Leaflet circleMarker position with Android GPS

androidgpsjavascriptleaflet

An Android code sends the latitude and longitude coords to a (html)Leaflet map (stored in Android Asset folder), which add a circleMarker to the actual poisiton.

function updateLocation(lat,lng,time){

map.panTo(new L.LatLng(lat,lng));

var circle = L.circleMarker([lat, lng], 10, {
    color: 'red',
    fillColor: '#f03',
    fillOpacity: 0.5
}).addTo(map);

I want to update the position, not to add to map again and again, when the GPS sends new positions. How can i fix it?

Best Answer

Solution:

if (marker) {
map.removeLayer(marker);
}
marker = new L.circleMarker([lat, lng]).addTo(map);
Related Question