问题描述
将代码从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个航点时,呼叫失败。这是自声明以来的预期结果
由于我没有在第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
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个路标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!