Reputation: 1990
I have this code for polyline which is working perfect. How do i add marker for each of location point?
var userCoor = [
<?php
for($i=0; $i<sizeOf($lat); $i++)
echo "new google.maps.LatLng({$lat[$i]}, {$long[$i]}),";
?>
];
var userCoordinate = new google.maps.Polyline({
path: userCoor,
strokeColor: "#FF0000",
strokeOpacity: 1,
strokeWeight: 2
});
userCoordinate.setMap(map);
I tried
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < userCoor.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(userCoor[i][1], userCoor[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(userCoor[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}
Marker seems missing? Any idea how? Thanks.
Upvotes: 3
Views: 16913
Reputation: 6779
I tested with some bogus data here and there doesn't seem to be a problem. The difference is I'm using userCoorPath
for the polyline and userCoor
to set the markers. I'm repeating the information, but they are being used differently. One is an array of LatLngs, the other an array of string and two floats.
Upvotes: 5
Reputation: 33738
You are not setting the marker icon
property.
Also, you are overwriting the marker variable. Perhaps that has something to do with it. try movinf your marker variable definition inside the loop.
Upvotes: 0