相关疑难解决方法(0)

如何确定坐标是否在当前可见的地图区域中?

我有几百个位置的列表,只想为当前屏幕上的那些位置显示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 */
  }
Run Code Online (Sandbox Code Playgroud)

所以我问convertCoordinate哪个点在屏幕上(除非我误解了这个方法很可能).如果坐标不在屏幕上,那么我从不将它添加到mapView.

所以我的问题是,这是确定位置的纬度/经度是否会出现在当前视图中并且应该添加到mapView的正确方法吗?或者我应该以不同的方式做这件事吗?

iphone cocoa-touch objective-c mapkit iphone-sdk-3.0

2
推荐指数
2
解决办法
6265
查看次数