gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 04:36:18 25 4
gpt4 key购买 nike

仅当我使用 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.

Google Maps - Direction Services Documentation

Here's the JsFiddle

关于javascript - Google Maps API (JS) 在航点中使用 PlaceId 创建路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36763790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com