访问谷歌地图API方向标记

3

我需要为方向标记添加监听器,但是没有任何访问权限。如何像简单标记一样获取方向标记的访问权限?抱歉我的英语很糟糕,希望你能理解我。

更新:我创建了一个新路线:

var request = {
    origin: someorigin,
    destination: somedestination,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status){
    if (status == google.maps.DirectionsStatus.OK){
        directionsDisplay.setDirections(response);
    }
});

现在我想要获取起点和终点标记的访问权限。


所以在使用DirectionsService后,您无法访问一些起点和终点标记吗? - KJYe.Name
但是,一些原点和一些目标地点是LatLng对象,而不是标记。 - Ardentum
它们是同一件事。只需使用addListener(marker, 'click', function())并在某个起点和目的地上创建一个标记。 - KJYe.Name
不幸的是,它没有解决我的问题。我需要准确地使用绿色标记的方向,而不是我的自己。 - Ardentum
@Ardentum 我建议你在jsfiddle.com上发布你的代码。 - KJYe.Name
显示剩余4条评论
3个回答

1

无法通过 google.maps.DirectionsRenderer 类访问添加到地图上的标记。不过,您可以使用 suppressMarkers 选项,呈现折线路线,然后使用自己的事件添加自己的起点和目标标记。

希望能帮到您。


1
谢谢。我考虑过这个方案,但是在我想拖动标记时会有一些限制。在这种情况下,我必须使用setinterval()并重新渲染路线。 - Ardentum

0

只需使用CSS:

有时候简单就是关键。

A行是一个表格:

<table id="adp-placemark" class="adp-placemark" jstcache="0">

而B线是:

<table class="adp-placemark" jstcache="0">

所以以下的 CSS 代码将会改变标记:

#adp-placemark img, .adp-placemark img {
   display:none;
}
#adp-placemark {
   font-weight: bold;
   padding: 10px 10px 10px 30px;
   background: white url(../images/map_icons/number_1.png) no-repeat left center;
}
.adp-placemark {
   font-weight: bold;
   padding: 10px 10px 10px 30px;
   background: white url(../images/map_icons/number_2.png) no-repeat left center;
}

-1

如果您正在使用API V3: 您可以在directionsDisplay对象中找到标记。

它们是:

directionsDisplay.b.d[0]
directionsDisplay.b.d[1]

因此,您可以对它们进行更改,例如将它们从地图上移除:

directionsDisplay.b.d[0].setMap(null);
directionsDisplay.b.d[1].setMap(null);

希望这可以帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接