我有几百个位置的列表,只想为当前在屏幕上的那些位置显示一个 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。
所以我的问题是,这是确定位置的纬度/经度是否会出现在当前视图中并应添加到地图视图中的正确方法吗?或者我应该以不同的方式做到这一点?