我有一个包含数百个位置的列表,只想在屏幕上显示当前可见的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 */
}
我想要将点应该在屏幕上的坐标转换一下(除非我误解了这种方法,这是很有可能的)。如果该坐标不在屏幕上,则我不会将其添加到地图视图中。
我的问题是,这是确定位置的纬度/经度是否出现在当前视图并应该添加到地图视图中的正确方法吗?还是我应该用另一种方式来做这件事?