仅当我使用 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
}
最佳答案
只需要通过 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
}
location specifies the location of the waypoint, as a LatLng, as a google.maps.Place object or as a String which will be geocoded.
关于javascript - Google Maps API (JS) 在航点中使用 PlaceId 创建路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36763790/