getDistanceFrom is nu verouderd dus hier is een alternatieve oplossing voor iedereen die op zoek om dit te doen.
CLLocationCoordinate2D pointACoordinate = [pointAAnnotation coordinate];
CLLocation *pointALocation = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];
CLLocationCoordinate2D pointBCoordinate = [pointBAnnotation coordinate];
CLLocation *pointBLocation = [[CLLocation alloc] initWithLatitude:pointBCoordinate.latitude longitude:pointBCoordinate.longitude];
float distanceMeters = [pointALocation distanceFromLocation:pointBLocation];
float distanceMiles = (distanceMeters / 1609.344);
[pointALocation release];
[pointBLocation release];
Zoals hierboven, kunt u gebruik maken floatin plaats van doubleen je kon de resultaten naar een int werpen als je niet de precisie van de eisen floatals volgt:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
Het intis handig als je wilde een ruw idee van afstand te geven in de aantekening als volgt:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
De ondertitel van het annotatie zou lezen "Afstand: 50m" bijvoorbeeld.