Чтобы настроить запрос на внешний сервер, я хочу получить границы текущего вида карты в приложении iPhone, которое я создаю. UIView должен реагировать на ограничения, но, похоже, MKMapView этого не делает. После настройки области и масштабирования на карте я пытаюсь получить границы. Я застрял на первом шаге, чтобы попытаться получить CGPoints, представляющие углы карты SE и NW. После этого я собирался использовать:
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
Чтобы преобразовать точки в координаты карты. Но я даже не могу зайти так далеко...
//Recenter and zoom map in on search location
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = mySearchLocation.searchLocation.coordinate;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[self.mapView setRegion:region animated:YES];
//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds
//First we need to calculate the corners of the map
CGPoint se = CGPointMake(self.mapView.bounds.origin.x, mapView.bounds.origin.y);
CGPoint nw = CGPointMake((self.mapView.bounds.origin.x + mapView.bounds.size.width), (mapView.bounds.origin.y + mapView.bounds.size.height));
NSLog(@"points are: se %@, nw %@", se, nw);
Код компилируется без предупреждений, однако se и nw равны нулю. Глядя на self.mapView.bounds.origin.x, переменная равна 0. Попытка NSLog непосредственно self.mapView.bounds.size.width дает мне "Программный полученный сигнал:" EXC_BAD_ACCESS "." который, как представляется, поступает из NSLog.
Кто-нибудь знает правильный способ получить юго-восточный угол и северо-западный угол (в координатах карты) из видимой области MKMapView?
РЕДАКТ: Кажется, что когда вы что-то задали, ответ приходит сразу после вас. Я использовал% @вместо @f для печати каждой переменной в NSLog, которая там бросала ошибки. Я также обнаружил свойство annotationVisibleRect для MKMapview. Кажется, что annotationVisibleRect основан на координатах родительского представления.