javascript 使用 Google 路线 API 问题绘制具有 8 个以上航点的路线图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19116578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drawing roadmap with more than 8 waypoints using Google directions API Issue
提问by Nullify
I am trying to draw road map with multiple waypoints.As per google API,you can use only 8 waypoint and for business development you can use only 23 waypoints but that is not enough to draw the accurate travel map.
我正在尝试绘制具有多个航点的路线图。根据 google API,您只能使用 8 个航点,对于业务开发,您只能使用 23 个航点,但这不足以绘制准确的旅行地图。
I got one notable solution link herebut did't works properly.
This solution has one issue for some point it wont't be able to draw the roadmap.
此解决方案在某些方面存在一个问题,即无法绘制路线图。
If you open my JSFiddlethe you can see that there are a brach of way points:
如果你打开我的JSFiddle,你会看到有一些路径点:
like:-
喜欢:-
var points = [[28.595161666666666, 77.31429666666666], [28.602561666666663, 77.31256166666667], [28.594639999999995, 77.30559166666667], [28.585825, 77.30017], [28.58475333333333, 77.30100333333333], [28.583985, 77.30347166666667], [28.584005, 77.30288], [28.584428333333335, 77.30269166666668], [28.584080000000004, 77.30304], [28.583235, 77.30358500000001], [28.584435, 77.30268333333333], [28.583306666666665, 77.30265666666666], [28.584278333333334, 77.30283833333333], [28.586365, 77.29805166666667], [28.583978333333334, 77.30177], [28.584324999999996, 77.30284166666667], [28.584238333333328, 77.30340666666666], [28.584101666666665, 77.30290666666666], [28.590111666666665, 77.30175666666668], [28.584323333333334, 77.30297333333333], [28.584215000000004, 77.30304666666666], [28.583788333333338, 77.30260666666666], [28.584193333333328, 77.303015], [28.583798333333334, 77.30157833333332], [28.584288333333333, 77.30296166666668], [28.583810000000003, 77.30295333333333], [28.583908333333337, 77.30201166666667], [28.58464333333333, 77.30217833333333], [28.584111666666665, 77.30134833333334], [28.587213333333338, 77.29757166666667], [28.58387, 77.29434666666666], [28.575966666666666, 77.28125833333334]]
VAR点= [[28.595161666666666,77.31429666666666],[28.602561666666663,77.31256166666667],[28.594639999999995,77.30559166666667],[28.585825,77.30017],[28.58475333333333,77.30100333333333],[28.583985,77.30347166666667],[28.584005,77.30288],[28.584428333333335,77.30269166666668 ],[28.584080000000004,77.30304],[28.583235,77.30358500000001],[28.584435,77.30268333333333],[28.583306666666665,77.30265666666666],[28.584278333333334,77.30283833333333],[28.586365,77.29805166666667],[28.583978333333334,77.30177],[28.584324999999996,77.30284166666667] [28.584238333333328,77.30340666666666],[28.584101666666665,77.30290666666666],[28.590111666666665,77.30175666666668],[28.584323333333334,77.30297333333333],[28.584215000000004,77.30304666666666],[28.583788333333338,77.30260666666666],[28.584193333333328,77.303015][28.583798333333334,77.30157833333332],[28.584288333333333,77.30296166666668],[28.583810000000003,77.30295333333333],[28.583908333333337,77.30201166666667],[28.58464333333333,77.30217833333333],[28.584111666666665,77.30134833333334],[28.587213333333338,77.29757166666667],[28.58387,77.29434666666666],[28.575966666666666 , 77.28125833333334]]
These data set('points') return an error as status
= ZERO_RESULTS
这些数据集('points') 返回错误为status
=ZERO_RESULTS
Now If you remove the last point ([28.575966666666666, 77.28125833333334]
) from the points array then this will work properly and status will be OK
.
现在,如果您[28.575966666666666, 77.28125833333334]
从点数组中删除最后一个点 ( ),那么这将正常工作并且状态将为OK
.
Why am I getting ZERO_RESULTS
instead of OK
? How can I skip those problematic points ?
为什么我得到ZERO_RESULTS
而不是OK
?我怎样才能跳过那些有问题的点?
Here is my JSFiddle :- http://jsfiddle.net/67tbw/28/
这是我的 JSFiddle :- http://jsfiddle.net/67tbw/28/
回答by Nullify
Finaly fixed it.Now it will work with any number of point and now status = ZERO_RESULTS
will not be a problem.
最后修复了它。现在它可以处理任意数量的点,现在status = ZERO_RESULTS
不会有问题。
The problem was for some points I was getting status=ZERO_RESULT
.After that it stopped executing and due to that I was not getting the map.So to fix that problem I came with the solution of skipping the particular point whenever status is not equal to OK
.Then proceed with the rest of the point. To do that i took two parameter one is for storing the last index and other is path. Because when I will not get OK status then I will not be able to get the lastIndx and path from the status so when ever i am getting the problem then it will go to the else part and there I did like this.
问题是我得到的一些点status=ZERO_RESULT
。之后它停止执行,由于我没有得到地图。所以为了解决这个问题,我提出了在状态不等于时跳过特定点的解决方案OK
。然后继续剩下的点。为此,我采用了两个参数,一个是用于存储最后一个索引,另一个是路径。因为当我无法获得 OK 状态时,我将无法从状态中获得 lastIndx 和路径,所以当我遇到问题时,它将转到其他部分,我就是这样做的。
1. lastIndx = lastIndx+1 ,
2. gDirRequest(service, waypoints, userFunction,lastIndx , path)
*call the function again until the last point.In between if I got status is OK then I will store the path as current path and lastIndx as current index (lastIndx = s[1]).
*再次调用该函数直到最后一个点。在两者之间,如果我的状态为 OK,那么我会将路径存储为当前路径,并将 lastIndx 存储为当前索引(lastIndx = s[1])。
check this JSFiddle: - http://jsfiddle.net/kousik/2pNKH/
检查这个 JSFiddle: - http://jsfiddle.net/kousik/2pNKH/