简体   繁体   English

使用Google Directions API问题绘制超过8个航点的路线图

[英]Drawing roadmap with more than 8 waypoints using Google directions API Issue

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. 我正在尝试绘制具有多个航点的路线图。根据谷歌API,您只能使用8个航点,而对于业务开发,您只能使用23个航点,但这还不足以绘制精确的旅行地图。

I got one notable solution link here but 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 JSFiddle the 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 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]] ,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 ? 为什么我得到ZERO_RESULTS而不是OK How can I skip those problematic points ? 我怎样才能跳过那些有问题的要点?

Here is my JSFiddle :- http://jsfiddle.net/67tbw/28/ 这是我的JSFiddle: - http://jsfiddle.net/67tbw/28/

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. 问题是我获得status=ZERO_RESULT一些点。之后它停止执行,因为我没有得到map.So为了解决这个问题我带来了解决方案,当状态不等于时,跳过特定点OK 。然后继续讨论其余部分。 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. 因为当我不能获得OK状态时,我将无法从状态获取lastIndx和路径,所以当我遇到问题时,它将转到else部分,我就是这样做的。

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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM