3

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:

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.

Jacob
  • 188
  • 1
  • 4
  • 13
Ardentum
  • 137
  • 1
  • 2
  • 10

3 Answers3

1

You can't access markers added to the map via the google.maps.DirectionsRenderer class. You can however use the suppressMarkers option, render the polyline route and then add your own start and destination markers with your own events.

Hope this helps.

Jacob
  • 188
  • 1
  • 4
  • 13
herostwist
  • 3,778
  • 1
  • 26
  • 34
  • 1
    Thank you. I thoght about it, but this solution have some limitations in case when i want to drag the marker. In this situation i must use setinterval() and render the route again. – Ardentum Apr 02 '11 at 21:25
0

Just use css:

Sometimes simplicity is key.

The A line is a table:

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

and B line is:

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

So the following css will change the markers:

#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;
}
Jason
  • 7,612
  • 14
  • 77
  • 127
-1

Provided you are using API V3: You can find the markers inside the directionsDisplay object.

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.

orenbnv
  • 39
  • 1