getDistanceFrom jest teraz przestarzała tak oto alternatywa odpowiedź dla każdego, kto chce to zrobić.
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];
Jak wyżej, można użyć floatzamiast doublei można rzucić wyniki do int, jeśli nie wymagają precyzji float, tak jak:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
intJest przydatny, gdy chciał dać z grubsza w odległości adnotacji tak:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
Podtytuł adnotacją będzie czytać „odległości: 50m” na przykład.