getDistanceFrom В настоящее время не рекомендуется, так вот альтернативный ответ для тех, кто ищет, чтобы сделать это.
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];
Как указано выше, можно использовать floatвместо doubleи вы могли бы привести результаты к междунар если вы не требуют точности floatтак:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
intОчень удобно , если вы хотите , чтобы дать общее представление о расстоянии в аннотации , как так:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
Подзаголовок аннотации будет читать «Расстояние: 50 м», например.