iPhone 开发 - 在可查看的地图区域中是 Pin 注释 [英] iPhone Development - Is Pin Annotation in a viewable Map Region

查看:25
本文介绍了iPhone 开发 - 在可查看的地图区域中是 Pin 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查图钉是否位于地图的可见区域 (MKMapView)?

How can i check if a pin is in viewable region of the map (MKMapView)?

推荐答案

一个 pin 是一个 MKPinAnnotationView,它继承自 MKAnnotationView 并且有一个属性 annotation(符合协议 MKAnnotation).这种注释本身具有另一个属性coordinate.

A pin is a MKPinAnnotationView, it extends from MKAnnotationView and has a property annotation (that conforms to the protocol MKAnnotation). Such annotation has itself another property coordinate.

只需将此类坐标的纬度/经度与地图区域进行比较即可.

Just compare the latitude / longitude of such coordinate to the region of your map.

这样的事情应该这样做:<代码>

double minLong = myMap.region.center.longitude - myMap.region.span.longitudeDelta/2.0;double maxLong = myMap.region.center.longitude + myMap.region.span.longitudeDelta/2.0;double minLat = myMap.region.center.latitude - myMap.region.span.latitudeDelta/2.0;double maxLat = myMap.region.center.latitude + myMap.region.span.latitudeDelta/2.0;

something like this should do it :

double minLong = myMap.region.center.longitude - myMap.region.span.longitudeDelta/2.0;
double maxLong = myMap.region.center.longitude + myMap.region.span.longitudeDelta/2.0;
double minLat = myMap.region.center.latitude - myMap.region.span.latitudeDelta/2.0;
double maxLat = myMap.region.center.latitude + myMap.region.span.latitudeDelta/2.0;

BOOL isPinInRegion = myPinCoordinates.longitude>=minLong &&myPinCoordinates.longitude<=maxLong &&myPinCoordinates.latitude>=minLat &&myPinCoordinates.latitude<=maxLat;

BOOL isPinInRegion = myPinCoordinates.longitude>=minLong && myPinCoordinates.longitude<=maxLong && myPinCoordinates.latitude>=minLat && myPinCoordinates.latitude<=maxLat;

这篇关于iPhone 开发 - 在可查看的地图区域中是 Pin 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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