one marker per coordinate on a polyline?

65 views
Skip to first unread message

fable

unread,
Sep 30, 2011, 7:51:49 PM9/30/11
to google-map...@googlegroups.com
Hi,

I'd like to put one marker on each set of coordinates on my polyline and haven't been able to figure it out.  Any ideas?


THANKS


xelawho

unread,
Sep 30, 2011, 10:33:05 PM9/30/11
to Google Maps JavaScript API v3
> I'd like to put one marker on each set of coordinates on my polyline and
> haven't been able to figure it out.  Any ideas?

why not put a marker on each set of coordinates on your polyline?

for (var g = 0; g < flightPlanCoordinates.length; g++) {
var marker = new google.maps.Marker({
position: flightPlanCoordinates[g],
map: map,
});
}

fable

unread,
Oct 2, 2011, 6:21:21 PM10/2/11
to google-map...@googlegroups.com
you make it sound so easy!  thank you - that was exactly what I was looking for :)

xelawho

unread,
Oct 3, 2011, 2:03:22 AM10/3/11
to Google Maps JavaScript API v3
it is pretty simple javascript. if you're going to be working with
arrays you should learn how to use the for loop - it does exactly what
both of your questions have asked (performs the same action/actions on
every member of the array). Your other question is a little trickier
because if you add the infowindow listener in a loop the variables get
overwritten (or that's how I understand it, anyway) but what I've
found easiest is to call a function from within the loop that adds a
listener to each marker, thus avoiding that problem:

var infowindow = new google.maps.InfoWindow();

for (var g = 0; g < flightPlanCoordinates.length; g++) {
var marker = new google.maps.Marker({
position: flightPlanCoordinates[g],
map: map,
});
addList(marker)
}

function addList(marker){
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
infowindow.setContent(marker.getPosition().lat()+","
+marker.getPosition().lng())
});
}

hope that helps
Reply all
Reply to author
Forward
0 new messages