나는 경도와 위도가 모두있는 배열을 가지고 있습니다. 내 사용자 위치에 두 개의 이중 변수가 있습니다. 내 배열과 내 사용자의 위치 간 거리를 테스트하여 가장 가까운 위치를 확인하고 싶습니다. 어떻게해야합니까?사용자 위치에서 가장 가까운 경도와 위도를 배열로 찾으십시오.
이것은 두 위치 사이의 거리를 가져 오지만 위치 배열에 대해 테스트하는 방법을 이해하기에 튼튼합니다.
CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:userlatitude longitude:userlongitude];
CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
CLLocationDistance distance = [startLocation distanceFromLocation:endLocation];
DOUBLE_MAX var은 무엇을 위해 사용됩니까? – user3626407
DOUBLE_MAX는 'smallestDistance' 변수를 가능한 가장 큰 수로 설정합니다. 아무것도 설정할 수 없지만 처음에 '100'으로 설정하면 배열에서 최소 거리가 실제로 '150'이면 문제가 발생합니다. – Fogmeister
@ Fogmeister "거리"대신 "smallestDistance"를 업데이트하지 않아야합니까? –