Google Maps API(JS)在航点中使用PlaceId创建路线 [英] Google Maps API (JS) Create a route using PlaceId in waypoints

查看:166
本文介绍了Google Maps API(JS)在航点中使用PlaceId创建路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当我使用LatLng或String params创建路线,但我需要通过PlaceId创建它,但它不起作用

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

示例:

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 例如:

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
}




位置指定航点的位置,作为LatLng,作为
google.maps.Place对象或作为将被地理编码的字符串。

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地图 - 定向服务文档

这里是JsFiddle

这篇关于Google Maps API(JS)在航点中使用PlaceId创建路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆