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

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

问题描述

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

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});  

这是我尝试将其转换为 V3

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);
    } 
});

不是整个代码,而是总体思路.似乎工作正常,有一个小问题.当航点超过 8 个时,调用失败.这是预期的,因为 Google Maps API v3 Docs 声明

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

允许的最大航路点为 8 个,加上起点和目的地.Maps API for Business 客户允许有 23 个航点,加上起点和终点.公交路线不支持航点.

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.

因为我在 v2 中没有遇到这个问题,这是 v3 的新限制吗?我想知道我是否使用了不是为我需要而设计的东西.这是一个非常容易使用的应用程序,有 2 个用户,所以我不确定昂贵的营业执照是否值得回报.发送给 Google 地图团队的电子邮件尚未返回.任何解决方法/指针都会有很大帮助.谢谢.

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.

推荐答案

一种可能的解决方法(特别是对于使用较少的站点)是使用多个 DirectionsService 请求.

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

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

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