简体   繁体   English

Google Maps Version 3删除路线标记

[英]Google Maps Version 3 Remove directions markers

Is there any way to remove the markers that the directions put on the map? 有什么方法可以删除路线在地图上放置的标记? I have 4 locations that show on the map. 我在地图上显示了4个位置。 A green arrow where the user is and 3 locations marked A, B, C. If I click on one it routes between the user's location and the marker. 用户所在的绿色箭头和标记为A,B,C的3个位置。如果我单击一个,它将在用户位置和标记之间路由。 The problem is that google adds a new A & B marker to the map as the start and end of the directions. 问题是Google向地图添加了一个新的A&B标记,作为路线的起点和终点。 Now I have a couple A and B markers on the map and it's pretty confusing. 现在我在地图上有几个A和B标记,这很令人困惑。

Thanks 谢谢

DirectionsRendererOptions设置suppressMarkerstrue

This is an old post, but I ran on the same issue. 这是旧文章,但我遇到了同样的问题。 I have map with my own markers, I would select few of them and starting point, then I would show directions with markers A, B, C... The problem was how to remove directions and show my markers again. 我有带有自己的标记的地图,我将选择其中几个标记和起点,然后使用标记A,B,C显示路线。问题是如何删除方向并再次显示标记。

Here is what worked for me to remove direction paths with markers (A, B, C, etc..). 这是我删除带有标记(A,B,C等)的方向路径的有效方法。

directionsDisplay.setMap(null);
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
RefreshMarkers(); //your function to draw your markers

directionDisplay is declared globally. directionDisplay是全局声明的。 It's API v3. 是API v3。

For each marker you want to remove, do 对于您要删除的每个标记,请执行

marker.setMap(null);

http://code.google.com/apis/maps/documentation/v3/overlays.html#Markers http://code.google.com/apis/maps/documentation/v3/overlays.html#Markers

Not sure if this is helpful or not. 不知道这是否有帮助。 When you create a new GDirection and supply it with a map object, it will automatically draw the polyline to the map as soon as the direction is loaded. 创建新的GDirection并为其提供地图对象时,一旦加载方向,它将自动将多段线绘制到地图上。 This also automatically adds the markers at the start and end of the journey. 这还将在旅程的开始和结束时自动添加标记。

I've noticed, however, that if you don't supply the map object initially and instead use the the 'load' event listener to manually add the polyline to the map, you get the line but not the markers. 但是,我注意到,如果您最初不提供地图对象,而是使用“加载”事件侦听器将折线手动添加到地图,则会得到直线,但不会得到标记。

//Don't supply a map to GDirections()
var direction = new GDirections(); 

//Make sure {getPolyline:true} is given to the load function
direction.load("here to there", {getPolyline:true});

GEvent.addListener(direction, 
                   "load", 
                   function(){ map.addOverlay(direction.getPolyline()); }
);

This might be easier than finding and removing the markers, especially if you're using the 'load' event listener anyway. 这可能比查找和删除标记更容易,尤其是如果您仍在使用“ load”事件监听器时。

Hit menu then layers and on the lower left press clear map. 点击菜单,然后分层,然后在左下角按清除地图。 That should clear out everything on the map. 那应该清除地图上的所有内容。

通常,您可以简单地做marker.setMap(null),但是由于Directions调用会自动在地图上放置A和B标记,因此您无法直接访问它们,因此无法以这种方式删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM