8

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.

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:

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]]

These data set('points') return an error as 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.

Why am I getting ZERO_RESULTS instead of OK ? How can I skip those problematic points ?

Here is my JSFiddle :- http://jsfiddle.net/67tbw/28/

Community
  • 1
  • 1
Kousik
  • 21,485
  • 7
  • 36
  • 59
  • Check this out [Easy Solution to the issue](http://stackoverflow.com/questions/8779886/exceed-23-waypoint-per-request-limit-on-google-directions-api-business-work-lev/39853476#39853476) – anupsahu Oct 04 '16 at 13:31
  • See my answer in similar question with full code example http://stackoverflow.com/questions/8779886/exceed-23-waypoint-per-request-limit-on-google-directions-api-business-work-lev/43458012#43458012 – mikep Apr 17 '17 at 20:06

1 Answers1

16

Finaly fixed it.Now it will work with any number of point and now status = ZERO_RESULTS will not be a problem.

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.

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]).

check this JSFiddle: - http://jsfiddle.net/kousik/2pNKH/

Kousik
  • 21,485
  • 7
  • 36
  • 59
  • 1
    Hi @Kousik, can you explain in your answer how you fixed it please? – CrazyTim Oct 04 '13 at 22:38
  • 1
    hey @CrazyTim.The problem was for some perticular point your code was getting status=ZERO_RESULT and after that it stopped executing and thats why I was not getting the map. so to fix that i am skipping the perticular point whenever i will get status not equal to OK.and 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. coz when i will not get OK status then i will not be able to get the lastIndx and path from the status.. read next comment – Kousik Oct 07 '13 at 13:27
  • 1
    so when ever i am getting the problem then it will go to the else part and there i did like this. 1. lastIndx = lastIndx+1 , 2. gDirRequest(service, waypoints, userFunction,lastIndx , path) *call the function again until the last point.and in between if i got status is OK then i store the path as current path and lastIndx as current index (lastIndx = s[1]). i think you got it.if you have some doubt i will clear. thanks – Kousik Oct 07 '13 at 13:28
  • be mindful you don't rely on this method too much for error catching as it will increase the number of calls to the API. – CrazyTim Oct 08 '13 at 02:04
  • I know it will increase the call but its fine for me.Have you any other solution? then please provide the jsFiddle. – Kousik Oct 08 '13 at 06:39
  • 3
    Nothing better than what you have done :). Also might be a good idea to provide feedback to the user on how many latlongs have been excluded from the route. – CrazyTim Oct 09 '13 at 00:20