Google maps API V3 - DirectionsRendererOptions and custom content in InfoWindow
Asked Answered
L

1

6

I am trying to implement a map/direction based application using Google maps V3 API. So far I have been able to display the map and show directions for two locations selected.

However I am unable to set custom content on the InfoWindow using DirectionsRendererOptions. Given below is what I am using.

var renderer = new google.maps.DirectionsRenderer(
                        {
                           infoWindow : new google.maps.InfoWindow(
                           {
                               content : "This is a test"
                           }
                         )}); 

It seems the custom InfoWindow is getting set, because when the disableAutoPan property is set on the new InfoWindow, the expected behavior happens. However the content is not set.

Is there a way that I can access the content of the InfoWindow (generated by DirectionsRenderer) and also update it ?

Thanks in advance.

Longstanding answered 26/5, 2011 at 14:6 Comment(1)
The InfoWindow in which to render text information when a marker is clicked. Existing info window content will be overwritten and its position moved. If no info window is specified, the DirectionsRenderer will create and use its own info window. This property will be ignored if suppressInfoWindows is set to true.Hettie
O
4

This won't 'update' your InfoWindow, rather it replaces it. So no event listeners and setContent.

In the callback for your directionsService.route, I simply modifed the content of response.routes[i].legs[j].end_address and response.routes[i].legs[j].start_address to HTML I wanted.

I'm not building a really complex application (plus I'm just learning the GMaps API for the first time) so this works for me.

Oliphant answered 29/7, 2014 at 2:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.