Я прошу прощения, если этот вопрос повторяется, но мне было трудно отобразить маршрут между двумя местами с помощью MKDirectionsRequest.
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = [MKMapItem mapItemForCurrentLocation];
request.transportType = MKDirectionsTransportTypeAny;
request.destination = _dstItem;
request.requestsAlternateRoutes = YES;
MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
// __block typeof(self) weakSelf = self;
[directions calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error) {
//stop loading animation here
if (error) {
NSLog(@"Error is %@",error);
} else {
//do something about the response, like draw it on map
MKRoute *route = [response.routes firstObject];
[self.mapView addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
}
}];
MKDirectionsResponse всегда возвращает nil с описанием ошибки
Error Domain=MKErrorDomain Code=5 "Directions Not Available"
UserInfo=0x1700f1c80 {NSLocalizedFailureReason=A route to the nearest road cannot be determined.,
MKErrorGEOError=-403, MKDirectionsErrorCode=6, NSLocalizedDescription=Directions Not Available}