外部サーバーへのクエリをセットアップするために、作成中の iPhone アプリで現在のマップ ビューの境界を取得したいと考えています。UIView は境界に応答する必要がありますが、MKMapView は応答しないようです。地域を設定してマップをズームした後、境界を取得しようとします。私は、マップの SE と NW のコーナーを表す CGPoints を取得しようとする最初のステップで立ち往生しています。その後、私は使用するつもりでした:
- (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 は両方とも null です。self.mapView.bounds.origin.x を見ると、変数は 0 です。NSLog を直接 self.mapView.bounds.size.width にしようとすると、「Program received signal: “EXC_BAD_ACCESS”.」というメッセージが表示されます。これは NSLog から来ているようです。
MKMapView の可視領域から南東の角と北西の角 (マップ座標) を取得する適切な方法を知っている人はいますか?
編集:ここで何かを尋ねると、すぐに答えが返ってくるようです。@f の代わりに %@ を使用して、そこにエラーをスローしていた NSLog の各変数を出力していました。また、MKMapview の annotationVisibleRect プロパティも発見しました。ですが、annotationVisibleRect は親ビューの座標に基づいているようです。