Google Maps displaying custom paths
I'm trying to customize the icons drawn by the GDirections object. I've got a list of lat long coordinates which I use to construct a path. However, I can't find any way of customizing (or even turning off) the markers that are automatically placed by the API.
var map;
map = new GMap2(document.getElementById("map_canvas"));
.... //get the path coordinates
var route = new GDirections(map);
route.load(path_coordinates);
Calling route.getPolyline().hide()
hides the path 开发者_开发百科but not the markers. Calling route.getMarker(1).isHidden()
returns true and obviously hiding it doesn't change anything.
Is this functionality not supported by the api?
I'm using map api 2.81
Try this code:
var map;
map = new GMap2(document.getElementById("map_canvas"));
.... //get the path coordinates
var route = new GDirections(map);
route.load(path_coordinates);
GEvent.addListener(route , "addoverlay", hideDirMarkers);
function hideDirMarkers(){
var numMarkers = route.getNumGeocodes()
for (var i = 0; i < numMarkers; i++) {
var marker = route.getMarker(i);
if (marker != null)
marker.hide();
else
alert("Marker is null");
}
}
精彩评论