- [ ] 현재 위치가 아닌 다른 위치에서 리프레쉬 버튼, 카테고리 버튼 선택 시 Distance 값이 현재 맵 위치 반경에서 거리를 방출하는 문제
- 현재 나의 위치에서의 거리 조정이 필요
import CoreLocation
// 함수를 통해 현재 위치에서 마커의 거리를 계산
func calculateDistanceFromCurrentLocation(to markerLocation: CLLocationCoordinate2D) {
guard let currentLocation = locationManager.location else {
print("Unable to retrieve current location.")
return
}
// 현재 위치
let currentCLLocation = CLLocation(latitude: currentLocation.latitude, longitude: currentLocation.longitude)
// 마커 위치
let markerCLLocation = CLLocation(latitude: markerLocation.latitude, longitude: markerLocation.longitude)
// 거리 계산 (단위: 미터)
let distance = currentCLLocation.distance(from: markerCLLocation)
print("Distance from current location to marker: \\(distance) meters")
}
// 예시: 마커의 위치 (위도, 경도)
let markerLocation = CLLocationCoordinate2D(latitude: 37.123456, longitude: 127.987654)
// 거리 계산 함수 호출
calculateDistanceFromCurrentLocation(to: markerLocation)
BaseRealm