MkMapView ha proprietà denominate centerCoordinate (CLLocationCoordinate2D) e regione (MKCoordinateRegion). Regione è una struttura che:
typedef struct {
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
}MKCoordinateSpan
Si dovrebbe essere in grado di creare un altro punto, sulla base di centerCoordinate, diciamo, con l'aggiunta di latitudeDelta a voi Latitude proprietà o centerCoordinate, e calcolare la distanza con il metodo di CLLocation:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Qualcosa di simile
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
E solo calcolare ogni volta che un delegato spara un certo metodo (decidere quale è necessario: MKMapViewDelegate)
Questa è una grande risposta. – sudo
ottima risposta! molte grazie! – Andres
'centerCoordinate.latitude + region.span.latitudeDelta' deve essere' centerCoordinate.latitude + region.span.latitudeDelta/2' per ottenere il raggio corretto. –