How to add a infowindow on DirectionsRenderer

978 views
Skip to first unread message

achick

unread,
Nov 16, 2010, 1:46:35 AM11/16/10
to Google Maps JavaScript API v3
I want to show a infoWindow when user click the route on map,
I had tried addListener on DirectionsRenderer and DirectionsRoute but
not work,
here is my code:

this.directionsService.route(param,function(result,
status){
if (status == google.maps.DirectionsStatus.OK) {
myDirectionsRenderer.setDirections(result);
if (param.content !== ""){
myDirectionsRenderer.infoWindow = new google.maps.InfoWindow({
content: param.content
});

google.maps.event.addListener(myDirectionsRenderer, 'click',
function(e) {
this.infoWindow.setPosition(e.latLng);
this.infoWindow.open(myMap);
});

}
}
});

Thanks.

geoco...@gmail.com

unread,
Nov 16, 2010, 6:35:23 PM11/16/10
to Google Maps JavaScript API v3
On Nov 15, 10:46 pm, achick <achick...@gmail.com> wrote:
> I want to show a infoWindow when user click the route on map,
> I had tried addListener on DirectionsRenderer and DirectionsRoute but
> not work,

You need to add a click listener to the polyline if you want it to
respond to clicks. The only way I know to do that is to use the
suppressPolylines option and draw it yourself.

One of my examples which does that:
http://www.geocodezip.com/v3_directions_custom_iconsC.html

> here is my code:

Not helpful. A link to your map might be.

-- Larry

> Thanks.

Chris Broadfoot

unread,
Nov 16, 2010, 10:21:22 PM11/16/10
to google-map...@googlegroups.com
Also, note in the context of an event listener, that 'this' is probably not the 'this' you're looking for.


> Thanks.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


achick

unread,
Nov 16, 2010, 10:22:24 PM11/16/10
to Google Maps JavaScript API v3
Thank you very much,and I'll do a page next time.

achick

unread,
Nov 16, 2010, 10:34:50 PM11/16/10
to Google Maps JavaScript API v3
That is because of the object infoWindow is stored in
myDirectionsRenderer,the object listened.
and in my practice, 'this' in the callback function will be equal to
the object listened.
isn't it?


On 11月17日, 上午11時21分, Chris Broadfoot <c...@google.com> wrote:
> Also, note in the context of an event listener, that 'this' is probably not
> the 'this' you're looking for.
>
> On Wed, Nov 17, 2010 at 10:35 AM, geocode...@gmail.com <geocode...@gmail.com
>
>
>
>
>
>
>
> > wrote:
> > On Nov 15, 10:46 pm, achick <achick...@gmail.com> wrote:
> > > I want to show a infoWindow when user click the route on map,
> > > I had tried addListener on DirectionsRenderer and DirectionsRoute but
> > > not work,
>
> > You need to add a click listener to the polyline if you want it to
> > respond to clicks.  The only way I know to do that is to use the
> > suppressPolylines option and draw it yourself.
>
> > One of my examples which does that:
> >http://www.geocodezip.com/v3_directions_custom_iconsC.html
>
> > > here is my code:
>
> > Not helpful.  A link to your map might be.
>
> >  -- Larry
>
> > > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages