Google Maps API(JS)在航点中使用PlaceId创建路线

Rom*_*shy 7 javascript google-maps direction google-maps-api-3

路由只有在我使用LatLng或String参数时才会创建,但我需要通过PlaceId创建它,但它不起作用

例:

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
    }
Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 5

只需要将google.maps.Place对象作为航点位置传递.例如:

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

location指定航点的位置,LatLng,google.maps.Place对象或将进行地理编码的String.

Google地图 - 指导服务文档

这是JsFiddle