在谷歌地图中指定保存的路点's方向服务

Specifying saved waypoints in Google Map's Directions Service

本文关键字:服务 方向 谷歌地图 保存      更新时间:2023-09-26

我遇到了一个问题,我从Google Maps API(V3)获取414 (Request-URI Too Large)状态,这基本上意味着我的GET请求中的查询字符串太长。问题是,这个GET请求是由DirectionsService路由函数自动创建的,所以我不太确定是否可以用其他方式来完成。有问题的代码:

//Setup a request object
var request = {
   origin: p1, //Point 1
   destination: p2, //Point 2
   optimizeWaypoints: true,
   travelMode: google.maps.TravelMode.DRIVING
};
//If we're editing a route that has been previously saved to file
if(editing !== false){
   //Specify the waypoints
   request.waypoints = routePoints;
}
directionsService.route(request, function(response, status) { 
    //Etc.
});

我采用了这种方法,将之前保存的路点附加到另一个问题的这个答案中的请求对象。基本上,request.waypoints应该是包含地图上的点的对象数组。然而,在较长的路线上,这个数组有时可以增长到200多个点,这显然解释了我得到的414代码。

允许的最大航路点为8,加上起点和终点。商务客户的地图API允许23个航路点,加上起点和终点。中转方向不支持航路点

谷歌地图API参考:方向服务

因此,对于包含200个路点的请求,不能使用DirectionsService.route