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

时间:2014-07-14 11:56:07

标签: ios mkmapview mkannotation

我有一个带有用户位置的MapView和一堆Map注释。

首先,我想在地图上显示所有可能的引脚。 (成功地做到了)

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

我如何找到这些注释?

2 个答案:

答案 0 :(得分:0)

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

CLLocationDistance dist = [loc1 distanceFromLocation:loc2];

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

答案 1 :(得分:0)

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

}

我认为它可能对你很有帮助。谢谢!!