getDistanceFrom jetzt veraltet ist, so ist hier eine alternative Lösung für jedermann, dies zu tun suchen.
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];
Wie oben erwähnt, könnten Sie floatstatt doubleund man konnte die Ergebnisse in einen int werfen , wenn Sie nicht die Präzision der erfordern floatso wie:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
Das intist praktisch , wenn Sie eine ungefähre Vorstellung davon Abstand in der Anmerkung wie so geben wollen:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
„: 50m Entfernung“ zum Beispiel der Untertitel der Anmerkung lesen würde.