A polyline is already been drawn a map, but how can markers be placed on it?
Current code:
map = new google.maps.Map(document.getElementById("map-canvas-tour"), mapOptions);
loadShowDates();
var polyFutureOptions = {
path: pathFutureCoordinates,
strokeColor: '#0000FF',
strokeOpacity: 0.8,
strokeWeight: 2.5
};
var polyPastOptions = {
path: pathPastCoordinates,
strokeColor: '#FF0000',
strokeOpacity: 0.6,
strokeWeight: 2.5
};
pathPast = new google.maps.Polyline(polyPastOptions);
pathFuture = new google.maps.Polyline(polyFutureOptions);
pathPast.setMap(map);
pathFuture.setMap(map);
infowindow = new google.maps.InfoWindow();
map.fitBounds(bounds);
There are two sets of points: pathFutureCoordinates and pathPastCoordinates and these refer to gigs in the past and gigs in the future all on a tour route (polyline). Each set of markers could be a different color.
What would I use to do this please?
Any other tips? A custom marker would be ideal.
Site page in question: http://goo.gl/H995E
Here’s a page where markers are placed either to extend the single polyline (click on the map), or when a spot in the polyline is clicked, a marker is added to the polyline. You can check if the new marker was correctly placed by dragging it and seeing the line adjust the segments.
https://files.nyu.edu/hc742/public/googlemaps/distance2.html
I’m not sure if you are planning to add new markers on the line by clicking or not. I will describe how the markers are added with clicks in the page above. Having a pre-built list of LatLngs would be a lot simpler (you only need steps 3 and 4 below).
A click listener is added to the line.
Because we need to know which segment was clicked, a helper function is called (isPointOnSegment)
Add marker and update marker position array:
Finally, redraw the line
For adding markers where there are pre-existing coordinates
http://jsfiddle.net/WZqgE/1/