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

标签 javascript google-maps google-maps-api-3 direction

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

相关文章:

javascript - Node JS 从 axios 返回数据

jquery - 谷歌地图的标记未在 iframe 中居中

javascript - 使用 Google map v3 在特定地址上放置图钉

php - 在 lat,lng 范围内查询

javascript - 如何在AngularJS中全屏显示谷歌地图

javascript - gulp - 完成时发出哔哔声

javascript - 让javascript取消jsp页面中的提交

javascript - Angular 模态 ui Bootstrap : Can i use another controller child of ModalInstanceCtrl?

javascript - 谷歌地图 API V3 : Snapping to nodes of another polygon

javascript - 禁用地理定位时,Google map 不会以位置为中心