从 Google Maps API V3 中删除路线标记 [英] Removing Directions markers from the Google Maps API V3

查看:42
本文介绍了从 Google Maps API V3 中删除路线标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从地图中删除普通标记,我知道您只需调用 marker.setMap(null),但是在实现 Google Maps 路线服务时,它会自动将标记 A 和 B 添加到地图上(计算从 A 点到B点).我无法控制这些标记,因此无法以正常方式删除它们.那么如何删除这些标记(我在地图上有自定义标记)?

To remove a normal marker from a map, I understand you simply call marker.setMap(null), but when implementing the Google Maps directions services, it automatically adds markers A and B onto the map ( calculating directions from point A to point B ). I do not have control over these markers, so I cannot remove them in the normal way. So how can I remove these markers (I have custom markers on the map instead)?

推荐答案

在创建 DirectionsRenderer 对象时将 suppressMarkers 选项设置为 true,然后标记将不显示向上.您还可以更改标记的样式或图标.有关您可以使用的其他属性,请参阅 DirectionsRendererOptions 的 API 规范设置.

Set the suppressMarkers option to true when creating your DirectionsRenderer object and then the markers won't show up. You could also change the style or icon of the markers. See the API spec for DirectionsRendererOptions for other properties you can set.

   ... 
   directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
   ...

从我大约 6 年前的原始答案以来,API 似乎发生了一些变化,所以来自 @joni-jones 的答案现在是正确的方法.我调整了上面的示例以反映这一点.

这篇关于从 Google Maps API V3 中删除路线标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆