How to move a marker on the map using an array of coordinates
Also i need to store the current position (or the index ) of the marker in a variable
example of array:
let data = [
["2019-06-28T07:33:03", 37.610225, 55.651365],
["2019-06-28T07:33:40", 37.6107283333333, 55.6511716666667],
["2019-06-28T07:33:46", 37.610745,55.6510383333333],
["2019-06-28T07:33:47",37.610785,55.6510233333333],
["2019-06-28T07:33:48",37.61083,55.65103]
];
i initialized the map and draw the path using Polyline based on the array :
function initMap() {
//start position
const startPosition ={lat:data[0][2],lng:data[0][1]}
let map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: myLocation,
});
const pathCoordinate = [];
data.forEach(path => {
pathCoordinate.push({
lat: path[2],
lng: path[1]
});
});
// draw the path
const principePath = new google.maps.Polyline({
path: pathCoordinate,
geodesic: true,
strokeColor: "#2A7884",
strokeOpacity: 1.0,
strokeWeight: 3,
icons: [
{
icon: currentPosition,
offset: "100%"
}
]
});
principePath.setMap(map);
}