Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps API V3 - DirectionsRendererOptions and custom content in InfoWindow

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.

like image 677
indit Avatar asked Oct 25 '22 10:10

indit


1 Answers

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.

like image 190
sammich Avatar answered Oct 31 '22 11:10

sammich