문제

I have an array of CLLocation objects. If I use

CLLocation *bestLocation = [locations valueForKeyPath:@"@min.horizontalAccuracy"];

I'm getting the lowest horizontalAccuracy value. But I want the OBJECT that contains the lowest value, so that I can later get it's proper coodinates. How can I do that?

I also tried with

CLLocation *bestLocation = [locations valueForKeyPath:@"@min.self.horizontalAccuracy"];

but got the same results.

Thanks

도움이 되었습니까?

해결책

I don't think there is a simple Key-Value Coding method for that, but you can loop over the array and keep track of the "best" element:

CLLocation *bestLocation = nil;
for (CLLocation *loc in locations) {
    if (bestLocation == nil || loc.horizontalAccuracy < bestLocation.horizontalAccuracy)
        bestLocation = loc;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top