Polyline and google maps marker together

I have this code for a polyline that works fine. How to add a marker for each 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)); } } 

Does the marker seem to be missing? Any idea how? Thanks.

+2
source share
2 answers

I tested with some dummy data here and there seems to be no problem. The difference is that I use userCoorPath for the polyline and userCoor for setting the markers. I repeat the information, but they are used in different ways. One of them is an array of LatLngs, the other is an array of strings and two floats.

http://jsfiddle.net/nSf9N/

+3
source

You do not set the marker property of icon .

In addition, you are rewriting the marker variable. Perhaps this is somehow connected with this. try changing the current definition of the marker variable inside the loop.

0
source

All Articles