如何找到符合我条件的地图注释 [英] How to find map annotations that fit my criteria
本文介绍了如何找到符合我条件的地图注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有用户位置的MapView和一堆Map注释.
I have a MapView with user location, and a bunch of Map annotations.
首先,我想在地图上显示所有可能的图钉. (成功完成此操作)
At first I want to show all the possible pins on the map. (succeeded in doing that)
然后我要放大地图,以仅显示距离userLocation注释50公里以内的注释
Then I want to zoom in the map to show only the annotations that are within 50 KMs away from the userLocation annotation
我如何找到这些注释?
推荐答案
- (CLLocation*)closestLocationToLocation:(CLLocation*)currLocation
{
CLLocationDistance minDistance;
CLLocation *closestLocation = nil;
for (CLLocation *location in arrayOfLocations) {
CLLocationDistance distance = [location distanceFromLocation:currLocation];
if (distance <= minDistance
|| closestLocation == nil) {
minDistance = distance;
closestLocation = location;
}
}
//closestLocation is now the location from your array which is closest to the current location or nil if there are no locations in your array.
return closestLocation;
}
我认为它可能对您很有帮助.谢谢!
I think Its May be Very Helpful to You.Thanks!!
这篇关于如何找到符合我条件的地图注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文