Psytronic
Psytronic

Reputation: 6113

Google Maps V3 Route Destination Mark Edit

Using the google.maps.DirectionsService.route() and google.maps.DirectionsRenderer.setDirections() method, is it possible to change the text on the info window for the destination, without creating a custom parser for the journey?

I couldn't see anything in the API which allowed you to access the markers of the route.

I don't want any code, just yes/no, and a hint for the right direction to take.

Current Function:

   var request = {
        origin: origPoint, 
        destination: new google.maps.LatLng(dest.lat(), dest.lng()),
        travelMode: google.maps.DirectionsTravelMode.DRIVING,
        region: "GB"
    };
    directionsService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(result);
        }
    });

Thanks, Psy

Upvotes: 3

Views: 1509

Answers (1)

Tomik
Tomik

Reputation: 23977

I'm afraid that the api doesn't offer a direct way to access the info windows or access the markers.

But there are several ways to achieve that parsing parts of the result data:

  1. I guess the simplest way to change text on the info window is to overwrite the DirectionsLegs' start and/or end addresses of the DirectionsResult. You have to do it before calling directionsDisplay.setDirections(result).
  2. Or you can display just the polyline (see suppressMarkers and suppressInfoWindows of renderer's options) and create the markers and infowindows yourself - you have to access data from DirectionsLegs of DirectionsResult.

I would prefer the second way since it's cleaner and you have more freedom in adjustments. The first way, it's only a hack and you are just changing the text.

Upvotes: 0

Related Questions