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

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?



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

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Please edit your answer to give some explanation as to how and where to use your code, and what it does. This then helps any users in the future that may have the same issue understand how to use your solution. – Midavalo Mar 11 '17 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.