I am very much new to leaflet and i hope that someone can help me. What im trying to do is adding two markers on the map and make another marker follow the route.
I have found a few plugins that would help but these plugins makes your marker over the map and not follow a specific route. .MovingMarker/
I know how it is done in google maps but not in leaflet.
I am very much new to leaflet and i hope that someone can help me. What im trying to do is adding two markers on the map and make another marker follow the route.
I have found a few plugins that would help but these plugins makes your marker over the map and not follow a specific route. http://ewoken.github.io/Leaflet.MovingMarker/
I know how it is done in google maps but not in leaflet. https://www.youtube./watch?v=zbr-F9wVqgU
Share Improve this question asked Mar 23, 2017 at 12:29 Wim PruiksmaWim Pruiksma 5981 gold badge5 silver badges19 bronze badges1 Answer
Reset to default 6You are close. You choosed the Leaflet plugin and have quite a precise goal. You just have to follow what is explained here.
Let's implement that :
// here is the path (get it from where you want)
var coordinateArray = [ [0,1], [1,1], [1,0] ];
// or for example
var coordinateArray = existingPolyline.getLatLngs();
// here is the line you draw (if you want to see the animated marker path on the map)
var myPolyline = L.polyline(coordinateArray);
myPolyline.addTo(map);
// i don't know if i understood your question correctly
// if you want to put a marker at the beginning and at the end of the path :
var mstart = L.marker(coordinateArray[0]).addTo(map);
var mend = L.marker(coordinateArray[coordinateArray.length - 1]).addTo(map);
// here is the moving marker (6 seconds animation)
var myMovingMarker = L.Marker.movingMarker(coordinateArray, 6000, {
autostart: false
});
map.addLayer(myMovingMarker);
myMovingMarker.start();