Patel Jigar
Patel Jigar

Reputation: 2151

MKDirectionsResponse object is giving null value

The response object is giving null and code is not executing.

MKPlacemark *source=[[MKPlacemark alloc]initWithCoordinate:sourceloc addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];  

MKPlacemark *source=[[MKPlacemark alloc]initWithCoordinate:sourceloc addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];

MKMapItem *srcmapItem=[[MKMapItem alloc]initWithPlacemark:source];

 [srcmapItem setName:@""];

MKPlacemark *destination=[[MKPlacemark alloc]initWithCoordinate:destinationloc addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];
MKMapItem *desmapItem=[[MKMapItem alloc]initWithPlacemark:destination];
 [desmapItem setName:@""];

MKDirectionsRequest *request=[[MKDirectionsRequest alloc]init];

 [request setSource:srcmapItem];
 [request setDestination:desmapItem];
 [request setTransportType:MKDirectionsTransportTypeWalking];

MKDirections *direction = [[MKDirections alloc]initWithRequest:request];

 [direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {

    NSLog(@"response = %@",response);
    NSArray *arrRoutes = [response routes];

    [arrRoutes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

        MKRoute *rout = obj;

        MKPolyline *line = [rout polyline];
        [self.routeMap addOverlay:line];
        NSLog(@"Rout Name : %@",rout.name);
        NSLog(@"Total Distance (in Meters) :%f",rout.distance);

        NSArray *steps = [rout steps];

        NSLog(@"Total Steps : %lu",(unsigned long)[steps count]);

        [steps enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            NSLog(@"Rout Instruction : %@",[obj instructions]);
            NSLog(@"Rout Distance : %f",[obj distance]);
        }];
    }];
}];

Upvotes: 1

Views: 465

Answers (1)

iTALIYA
iTALIYA

Reputation: 852

Directions Feature Availability list in apple officials

https://www.apple.com/in/ios/feature-availability/#maps-directions

So this Feature is not available in INDIA as per apple documentation.That is only reason for getting NULL response.

you can use Google map with some limitations, The Google Maps Geocoding API has below limits.

https://developers.google.com/maps/documentation/geocoding/usage-limits

Other alternate solution is to use other open source.

Upvotes: 1

Related Questions