如何知道MKMapView visibleMapRect是否包含Coordinate? [英] How to know whether MKMapView visibleMapRect contains a Coordinate?

查看:119
本文介绍了如何知道MKMapView visibleMapRect是否包含Coordinate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有MKMapView和CLLocationCoordinate2D,你如何测试地图的可见区域是否包含坐标?

If I have a MKMapView and a CLLocationCoordinate2D how do you test whether the map's visible area contains the coordinate?

推荐答案

最快的方法是使用内置的Apple功能,这将使这种事情变得非常快!

The fastest way is to use the inbuilt Apple functions which will make this sort of thing super quick!

if(MKMapRectContainsPoint(mapView.visibleMapRect, MKMapPointForCoordinate(coordinate)))
{
    //Do stuff
}

其中坐标是你的CLLocation2D。

Where coordinate is your CLLocation2D.

这比使用批量if语句计算坐标要快得多。原因是Apple使用Quadtree并且可以为您快速查找。

This will be much faster than working out coordinates with a bulk if statement. Reason is that Apple use a Quadtree and can do fast lookups for you.

这篇关于如何知道MKMapView visibleMapRect是否包含Coordinate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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