简体   繁体   English

访问Google Maps API方向标记

[英]Access to google maps api directions markers

I need to add listeners for directions markers, but haven't any access. 我需要为方向标记添加侦听器,但没有任何访问权限。 How can I get access to direction markers like simple markers? 如何获得诸如简单标记之类的方向标记? Sorry for my terrible English, I hope you can understand me. 对不起,我的英语不好,希望您能理解我。

UPD: I create a new route: UPD:我创建了一条新路线:

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

And now I want to get access to the origin and destination markers. 现在,我想访问起点和终点标记。

Just use css: 只需使用CSS:

Sometimes simplicity is key. 有时候,简单是关键。

The A line is a table: A行是一个表:

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

and B line is: B线是:

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

So the following css will change the markers: 因此,以下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;
}

You can't access markers added to the map via the google.maps.DirectionsRenderer class. 您无法通过google.maps.DirectionsRenderer类访问添加到地图的标记。 You can however use the suppressMarkers option, render the polyline route and then add your own start and destination markers with your own events. 但是,您可以使用preventMarkers选项,渲染折线路线,然后在您自己的事件中添加自己的起点和终点标志。

Hope this helps. 希望这可以帮助。

Provided you are using API V3: You can find the markers inside the directionsDisplay object. 假设您正在使用API​​ V3:您可以在directionsDisplay对象内找到标记。

they are: 他们是:

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

Accordingly, you can make changes to them, such as take them off the map: 因此,您可以对其进行更改,例如将其从地图上移开:

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

Hope this helps. 希望这可以帮助。

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

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