How to get one or more possible routes between two points? If anybody has worked on this can you please tell me?
Multiple Routes Between two Locations in Mkmapview
1.7k views Asked by Vikas Rajput At
2
There are 2 answers
0
On
use this :-
NSString *baseUrl=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json? origin=indore&destination=bhopal&key=%@&alternatives=true”,APIKey];
NSURL *url = [NSURL URLWithString:[baseUrl
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionConfiguration *defaultConfigObject =
[NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:
defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil)
{
NSDictionary *result= [NSJSONSerialization JSONObjectWithData:data
options:0 error:nil];
// this will return all possible roots
NSArray *routes = [result objectForKey:@"routes"];
//add The polyline between locations.
}
}];
[dataTask resume];

Using MapKit
You need to make your
[directionRequest setRequestsAlternateRoutes:YES]then inresponse.routesyou will get the available routesFull code
Objective-C
Swift
Hope this helps