MKMapView hat Eigenschaften genannt centerCoordinate (CLLocationCoordinate2D) und Umgebung (MKCoordinateRegion). Region ist eine Struktur, die:
typedef struct {
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
}MKCoordinateSpan
Sie sollten in der Lage sein, einen anderen Punkt zu erstellen, basierend auf centerCoordinate, sagen wir mal, durch Zugabe von latitudeDelta Sie Breiten- Eigentum oder centerCoordinate und berechnen Entfernung mit der Methode der CLLocation:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
So etwas wie diese
MkMapView * mapView; // init somewhere
MKCoordinateRegion region = mapView.region;
CLLocationCoordinate2D centerCoordinate = mapView.centerCoordinate;
CLLocation * newLocation = [[[CLLocation alloc] initWithLatitude:centerCoordinate.latitude+region.span.latitudeDelta longitude:centerCoordinate.longitude] autorelease];
CLLocation * centerLocation = [[[CLLocation alloc] initWithLatitude:centerCoordinate.latitude:longitude:centerCoordinate.longitude] autorelease];
CLLocationDistance distance = [centerLocation distanceFromLocation:newLocation]; // in meters
Und berechnen nur jedes Mal, wenn ein Delegierter eine bestimmte Methode feuert (entscheiden, die Sie brauchen: MKMapViewDelegate)
Dies ist eine großartige Antwort. – sudo
große Antwort! Danke vielmals! – Andres
'centerCoordinate.latitude + region.span.latitudeDelta' muss' centerCoordinate.latitude + region.span.latitudeDelta/2' sein, um den richtigen Radius zu erhalten. –