4

I want to display driving path on google map using api v2. I have a source, destination and some way point between those two points. and for this I am using below code and it works fine, but problem is when i have less then 10 points then it works find but when i added more then 10 points then api returns error.

below is my code for generating url -

api -
https://maps.googleapis.com/maps/api/directions/json?

code -

public static String getDirectionsUrl(LatLng origin,LatLng dest,ArrayList<LatLng> mLatLongAL,String url){
    try{
        String str_origin = "origin="+origin.latitude+","+origin.longitude;
        String str_dest = "destination="+dest.latitude+","+dest.longitude;
        String sensor = "sensor=false";
        String waypoints = "";
        for(int i=0;i<mLatLongAL.size();i++){
            LatLng point  = (LatLng) mLatLongAL.get(i);
            if(i==0)
                waypoints = "waypoints=";
            waypoints += point.latitude + "," + point.longitude + "|";
        }
        String parameters = str_origin+"&"+str_dest+"&"+sensor+"&"+waypoints;
        String mUrl = url+parameters;
        return mUrl;
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return null;
}

how to get path for more then 10 way points.

Thanks in Advance.

Guess
  • 238
  • 1
  • 2
  • 13

1 Answers1

0

Using Google's Direction API, you are limited to only up to 8 waypoints with the free version. Not sure how you're getting 10 if you're using the free version. To get more waypoints for a request, you'll need to get Google Maps API for Work, which will allow you up to 23 waypoints. You can refer to the documentation here.

Andy
  • 2,374
  • 3
  • 17
  • 20