1

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?

0

Solution:

if (marker) {
map.removeLayer(marker);
}
marker = new L.circleMarker([lat, lng]).addTo(map);
| improve this answer | |
  • 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.