我的应用程序中有一堆存储的路由地址,但是开始使用自动完成的place_id来处理新请求。如果在自动填充字段('place_changed')中修改了地址,我有一个场景,我用place_id和字符串提交请求。
我没有看到任何暗示文档中不允许的内容,但是当返回结果时,它似乎只使用为起点和终点提供的place_id。
您可以在下面复制它。我做错了什么?
var directionsService = new google.maps.DirectionsService();
var routeRequest = {
avoidHighways: false,
avoidTolls: false,
destination: "19170 Geyserville Ave, Geyserville, CA 95441, USA",
optimizeWaypoints: false,
origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
provideRouteAlternatives: false,
travelMode: "DRIVING",
waypoints: []
}
directionsService.route(routeRequest, function( result, status ) {
console.log(result);
console.log(status);
});
以上产量:
result.routes[0].legs[0].startAddress = "Best Western Dry Creek Inn, 198 Dry Creek Rd, Healdsburg, CA 95448, USA"
result.routes[0].legs[0].endAddress = "Best Western Dry Creek Inn, 198 Dry Creek Rd, Healdsburg, CA 95448, USA"
答案 0 :(得分:1)
这看起来像API中的错误。使用LatLng或placeId作为目标工作,但使用地址或“地点”查询不会。
这些不起作用:
var routeRequest = {
origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
destination: {query: "19170 Geyserville Ave, Geyserville, CA 95441, USA"},
travelMode: "DRIVING"
}
var routeRequest1 = {
origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
destination: "19170 Geyserville Ave, Geyserville, CA 95441, USA",
travelMode: "DRIVING"
}
这样做:
var routeRequest2 = {
origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
destination: {location: {lat:38.679366,lng:-122.872864}},
travelMode: "DRIVING"
}
var routeRequest3 = {
origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
destination: new google.maps.LatLng(38.679366,-122.872864),
travelMode: "DRIVING"
}