开发者

Google Maps displaying custom paths

开发者 https://www.devze.com 2022-12-22 08:44 出处:网络
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 tur

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号