开发者

Google maps v3 driving directions with a clickable route / infowindow

I'm plotting driving directions on google map using the v3 api.

I'd like to add a listener so that if someone clicks on any point of the route that I can open an infowindow.

I can do this with a polyline:

google.maps.eve开发者_JAVA百科nt.addListener(mapEntry, 'click', function (e) {
    infowindow.position = e.latLng;
    infowindow.open(map);
});

I've tried to attach the click event to the following items in the directions response:

response.route[0].overview_path
response.route[0].overview_polyline
response.route[0].overview_polyline.points

But no luck. Can't even hit the click event. Any ideas?


Did you ever try the solution below? It is a trigger function of Google Maps, maybe it can help you..

google.maps.event.trigger(mapEntry, 'click', function(){
//do other things
});


you can try this, it works for me After calling the modirectionsDisplay.setDirections(response); call

   setTimeout(function () {
       try {
           modirectionsDisplay.j.polylines.forEach(function (polyline) {
                //attach event listener
            });
       } catch (e) {
           alert(e);
       }
   }, 200);

It's not the best development method but it works. Also you must disable the draggable option in DirectionsRenderer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜