2010-03-04 73 views
1

我试图自定义由GDirections对象绘制的图标。我有一个我用来构造路径的经纬度坐标列表。但是,我找不到任何自定义(甚至关闭)由API自动放置的标记的方法。谷歌地图显示自定义路径

var map; 
map = new GMap2(document.getElementById("map_canvas")); 
.... //get the path coordinates 
var route = new GDirections(map); 
route.load(path_coordinates); 

调用route.getPolyline().hide()隐藏路径而不是标记。调用route.getMarker(1).isHidden()返回true,显然隐藏它不会改变任何东西。 这个功能不被api支持吗? 我使用的地图API 2.81

回答

1

试试这个代码:

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"); 
     } 
} 
+0

感谢您的回答。我正在尝试同样的事情,但使用'load'事件。 – Pavel 2010-03-04 12:05:53