getDistanceFrom er nå foreldet, så her er en alternativ løsning for alle som ønsker å gjøre dette.
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];
Som ovenfor, kan du bruke floati stedet for double, og du kan kaste resultatene til en int hvis du ikke krever presisjon av den floatslik:
int distanceCastToInt = (int) [pointALocation distanceFromLocation:pointBLocation];
Det inter nyttig hvis du ønsket å gi en viss idé om avstand i merknaden som så:
pointAAnnotation.title = @"Point A";
pointAAnnotation.subtitle = [NSString stringWithFormat: @"Distance: %im",distanceCastToInt];
Undertittelen på merknaden ville lese "Avstand: 50m" for eksempel.