MKDirectionsRequest between two given points on the map

I have the following code that always returns me "Unable to determine the route" (or something similar, the message is changing)

   -(void)getPathDirections:(CLLocationCoordinate2D)source withDestination:(CLLocationCoordinate2D)destination{

MKPlacemark *placemarkSrc = [[MKPlacemark alloc] initWithCoordinate:source addressDictionary:nil];
MKMapItem *mapItemSrc = [[MKMapItem alloc] initWithPlacemark:placemarkSrc];
MKPlacemark *placemarkDest = [[MKPlacemark alloc] initWithCoordinate:destination addressDictionary:nil];
MKMapItem *mapItemDest = [[MKMapItem alloc] initWithPlacemark:placemarkDest];
[mapItemSrc setName:@"name1"];
[mapItemDest setName:@"name2"];

MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
[request setSource:mapItemSrc];
[request setDestination:mapItemDest];
[request setTransportType:MKDirectionsTransportTypeAutomobile];
request.requestsAlternateRoutes = NO;

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

[directions calculateDirectionsWithCompletionHandler:
 ^(MKDirectionsResponse *response, NSError *error) {
     if (error) {
         // Handle Error
     } else {
         [_mapView removeOverlays:_mapView.overlays];
         [self showRoute:response];
     }
 }];

}

I am in Romania and my country is on the Apple list with route-supported countries.

I can also follow the route between my current position and the marker on the map ...

Any ideas?

+4
source share
1 answer

. , , , . , . - Google Latitude Longitude , .

P.S Latitude Longitude. - :)

:

source =  CLLocationCoordinate2DMake(24.51898765563965, 44.26686859130859); 
destination = CLLocationCoordinate2DMake(24.3679256439209, 44.10536575317383);

:

source =  CLLocationCoordinate2DMake(44.26686859130859, 24.51898765563965); 
destination = CLLocationCoordinate2DMake(44.10536575317383, 24.3679256439209);
+3

Source: https://habr.com/ru/post/1542502/


All Articles