Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API (JS) Create a route using PlaceId in waypoints

The route create only if I use LatLng or String params but I need create it by PlaceId but it doesn't work

example:

directionsService.route({
        origin: {'placeId': 'ChIJc1lGdwfP20YR3lGOMZD-GTM'},
        destination: {'placeId': 'ChIJdTGhqsbP20YR6DZ2QMPnJk0'},
        waypoints: [{stopover: true, location: new google.maps.Place('ChIJRVj1dgPP20YRBWB4A_sUx_Q')}],
        optimizeWaypoints: true,
        travelMode: google.maps.TravelMode.DRIVING
    }
like image 617
Roman Konushy Avatar asked Apr 21 '16 08:04

Roman Konushy


1 Answers

Just need to pass the google.maps.Place object as the waypoint location. For example:

directionsService.route({
    origin: { placeId: "ChIJc1lGdwfP20YR3lGOMZD-GTM" },
    destination: { placeId: "ChIJdTGhqsbP20YR6DZ2QMPnJk0" },
    waypoints: [{ stopover: true, location: { placeId: "ChIJRVj1dgPP20YRBWB4A_sUx_Q" } }],
    optimizeWaypoints: true,
    travelMode: google.maps.TravelMode.DRIVING
}

location specifies the location of the waypoint, as a LatLng, as a google.maps.Place object or as a String which will be geocoded.

Google Maps - Direction Services Documentation

Here's the JsFiddle

like image 159
Chris Avatar answered Oct 19 '22 23:10

Chris