Я должен знать расстояние (в километрах) от центральной карты до другой стороны экрана, (и если изменение масштабирования расстояние изменится).
Я должен реализовать эту опцию в этой функции
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
}
Какие-либо идеи, как я могу сделать это?
Спасибо
MkMapView имеет свойства с именами centerCoordinate (CLLocationCoordinate2D) и region (MKCoordinateRegion) . Регион - это структура, которая:
typedef struct {
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
}MKCoordinateSpan
Вы должны иметь возможность создать другую точку на основе centerCoordinate, скажем, добавив latitudeDelta к вашему свойству latitude или centerCoordinate, и вычислить расстояние, используя метод CLLocation:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Что-то вроде этого
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
И просто вычисляйте каждый раз, когда делегат запускает определенный метод (решите, какой вам нужен: MKMapViewDelegate)