Connect Multiple Markers With Polyline
I tried this code but no luck with polylines,may be because of small issue, i couldn't get polylines that connect the markers. I need to connect multiple marker with polylines any
Solution 1:
flightPath should be called as an array.
Please try this updated code.
var locations = [
];
// call php arrayvar latitude = <?phpecho json_encode($latitude); ?>;
var longitude = <?phpecho json_encode($longitude); ?>;
for(var i=0;i<20;i++){
locations.push(["current",latitude[i], longitude[i]]);
}
var marker;
functioninitMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: new google.maps.LatLng(12.289774217827633, 76.30976921188685)
});
// locations.push(["current",test2, test3]);var infowindow = new google.maps.InfoWindow();
var marker, i;
var flightPlanCoordinates = [];
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
flightPlanCoordinates.push(marker.getPosition());
google.maps.event.addListener(marker, 'click', (function(marker, i) {
returnfunction() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
var flightPath = new google.maps.Polyline({
map: map,
path: flightPlanCoordinates,
strokeColor: "#ff0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
}
Post a Comment for "Connect Multiple Markers With Polyline"