In mijn programma heb ik MKDirections om een (loop) afstand te krijgen tussen twee locatie.
CLLocationCoordinate2D startCoordinates = YOUR_START_COORDINATES;
CLLocationCoordinate2D endCoordinates = YOUR_END_COORDINATES;
MKPlacemark *startPoint = [[MKPlacemark alloc] initWithCoordinate:startCoordinates];
MKPlacemark *endPoint = [[MKPlacemark alloc] initWithCoordinate:endCoordinates];
MKMapItem *startItem = [[MKMapItem alloc] initWithPlacemark:startPoint];
MKMapItem *endItem = [[MKMapItem alloc] initWithPlacemark:endPoint];
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = startItem;
request.destination = endItem;
request.transportType = MKDirectionsTransportTypeAutomobile; //here you can choose a transport type you need
MKDirections *direction = [[MKDirections alloc] initWithRequest:request];
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * _Nullable response, NSError * _Nullable error) {
if (response) {
for (MKRoute *route in response.routes) {
NSLog(@"Distance : %f", route.distance);
}
}
}];
als je je locatie als een adres, zodat u de methode van CLGeocoder, die geeft je de lengte- en breedtegraad van uw adres te gebruiken
- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler;
Als u een rij-afstand resultaat met behulp van MKDirections met degene die met behulp van Google Maps te vergelijken, zul je zien dat ze verschillen. Ik was op zoek met betrekking tot deze zaak en kwam over de volgende link http://www.macworld.co.uk/review/reference-education/apple-maps-vs-google-maps-3464377/
Hoewel Apple zijn het verbeteren van hun kaartdienst, ze nog steeds toe te geven in de nauwkeurigheid bij Google (IMO), ten minste in een vraag over de rij-afstand. Dus als nauwkeurigheid is niet zeer belangrijk in uw geval, zodat je samen kunt volgen met Apple. Anders zou ik aanraden om Google API.