如何find符合我的标准的地图注释

我有一个MapView的用户位置,和一堆地图注释。

起初我想在地图上显示所有可能的引脚。 (成功做到这一点)

然后,我想放大地图以仅显示距离userLocation注释50公里内的注释

我如何find这些注释?

- (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; } 

我觉得它可能对你有帮助。谢谢!

您必须使用以下命令计算引脚和用户位置之间的距离:

 CLLocationDistance dist = [loc1 distanceFromLocation:loc2]; 

loc1和loc2是CLLocation对象。 您必须使用此距离参数来过滤引脚数组。