getDistanceFrom mára elavulttá, így itt egy alternatív válasz mindazok számára, akik ezt.
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];
Mint fent, akkor használja floatahelyett, doubleés meg tudná leadott eredmények egy int, ha nincs szükség a pontosság az floatígy néz ki:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
A intpraktikus, ha azt akarta, hogy egy durva ötlet távolság a kommentár így:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
Az alcím A kommentár lenne: „Távolság: 50m” például.