在Google Maps v3中绘制超过8个路标 [英] Plotting more than 8 waypoints in Google Maps v3

查看:101
本文介绍了在Google Maps v3中绘制超过8个路标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将代码从Javascript API 2迁移到3.我有一个位置列表,我需要以驾驶路线的形式进行绘制。这是在v2中使用以下代码完成的:

  directions = new GDirections(map); 
directions.loadFromWaypoints(waypoints,{preserveViewport:true});

以下是我将它转换为V3的尝试

  var request = {
origin:startLoc,
destination:endLoc,
航点:航点,
optimizeWaypoints:true,
travelMode:google.maps.TravelMode.DRIVING
};

directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
}
});

不是整个代码,而是一般想法。似乎工作正常,只有一个小问题。当有超过8个航点时,呼叫失败。这是自 Google Maps API v3文档声明以来的预期结果


最大允许航点是8,加上起点和目的地。 Maps API for Business客户可以使用23个航点,以及出发地和目的地。


由于我没有在第2版中遇到这个问题,这是一个新的限制吗? V3?我想知道我是否在使用那些没有为我需要的东西而设计的东西。这是一个非常少用的应用程序与2个用户,所以我不知道如果昂贵的营业执照是值得的回报。 Google地图团队的电子邮件尚未返回。任何解决方法/指针都会有很大的帮助。感谢。

解决方案

一个可能的解决方法是使用多个DirectionsService请求。


Migrating code from Javascript API 2 to 3. I have a list of locations which i need to plot in the form of a driving directions. This was done in v2 using the following code

directions = new GDirections(map);
directions.loadFromWaypoints(waypoints, {preserveViewport: true});  

Here is my attempt at converting this to V3

var request = {
    origin: startLoc,
    destination: endLoc,
    waypoints: waypoints,
    optimizeWaypoints: true,
    travelMode: google.maps.TravelMode.DRIVING
};          

directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
    } 
});

Not the whole code, but the general idea. Seems to work fine, with one little issue. When there are more than 8 waypoints, the call fails. This is expected since Google Maps API v3 Docs states

The maximum allowed waypoints is 8, plus the origin, and destination. Maps API for Business customers are allowed 23 waypoints, plus the origin, and destination. Waypoints are not supported for transit directions.

Since i didn't run in to this issue in v2, is this a new restriction with v3? I wonder if i am using something that was not designed for what i need. This is a very lightly used applicaton with 2 users, so i am not sure if an expensive business license is worth the return. Emails to Google maps team have not yet been returned. Any workarounds/pointers will be of great help. Thanks.

解决方案

One possible work around (particularly for a lightly used site) is to use multiple DirectionsService requests.

这篇关于在Google Maps v3中绘制超过8个路标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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