如何确定坐标是否位于当前可见的地图区域中? [英] How do I determine if a coordinate is in the currently visible map region?

查看:288
本文介绍了如何确定坐标是否位于当前可见的地图区域中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几百个位置的列表,并且只想显示当前在屏幕上的那些位置的MKPinAnnotation。屏幕以用户当前位置以2英里半径开始。当然,用户可以在屏幕上滚动和缩放。现在,我等待地图更新事件,然后循环通过我的位置列表,并检查像这样的坐标:

I have a list of several hundred locations and only want to display an MKPinAnnotation for those locations currently on the screen. The screen starts with the user's current location with a 2 mile radius. Of course, the user can scroll, and zoom on the screen. Right now, I wait for a map update event, and then loop through my location list, and check the coordinates like this:

-(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。

So I am asking convertCoordinate where the point would be on the screen(unless I misunderstand this method which is very possible). If the coordinate isn't on the screen, then I never add it to the mapView.

所以我的问题是,这是正确的方式来确定一个位置的纬度/经度将出现在当前视图,应该添加到mapView?

So my question, is this the correct way to determine if a location's lat/long would appear in the current view and should be added to the the mapView? Or should I be doing this in a different way?

推荐答案

经过一点点阅读后,我找不到任何说明这是一个坏主意。我已经做了一些测试在我的应用程序,我总是得到正确的结果。当我只添加显示在当前可见的地图区域中而不是一次显示所有300个坐标的坐标时,该应用加载得更快。

After a little bit of reading I can't find anything that says this is a bad idea. I've done a bit of testing in my app and I always get correct results. The app loads much quicker when I only add coordinates that will show up in the currently visible map region instead of all the 300+ coordinates at once.

我在找什么是一个像[mapView isCoordinateInVisibleRegion:myCoordinate]这样的方法,但是到目前为止这个方法很快,看起来很准确。

What I was looking for was a method like [mapView isCoordinateInVisibleRegion:myCoordinate], but so far this method is quick and seems accurate.

我也把标题改为地图区域而不是以前的,因为我认为不正确的标题可能会混淆我的意思。

I've also changed the title to read "in the visible map region" instead of the previous because I think the incorrect title may have confused my meaning.

这篇关于如何确定坐标是否位于当前可见的地图区域中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆