数百の場所のリストがあり、現在画面に表示されている場所の MKPinAnnotation のみを表示したいと考えています。画面は、半径 2 マイルのユーザーの現在地から始まります。もちろん、ユーザーは画面をスクロールしたり、ズームしたりできます。現在、マップの更新イベントを待ってから、場所リストをループして、次のように座標を確認します。
-(void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
CGPoint point;
CLLocationCoordinate2D coordinate;
. . .
/* in location loop */
coordinate.latitude = [nextLocation getLatitude];
coordinate.longitude = [nextLocation getLongitude];
/* Determine if point is in view. Is there a better way then this? */
point = [mapView convertCoordinate:coordinate toPointToView:nil];
if( (point.x > 0) && (point.y>0) ) {
/* Add coordinate to array that is later added to mapView */
}
したがって、ポイントが画面上のどこにあるかconvertCoordinateに尋ねています(この方法を誤解していない限り、非常に可能性があります)。座標が画面上にない場合は、mapView に追加しません。
私の質問は、場所の緯度/経度が現在のビューに表示され、mapView に追加する必要があるかどうかを判断する正しい方法ですか? または、これを別の方法で行う必要がありますか?