(Offline) Geocoder - kirseia/study GitHub Wiki
GPS 좌표로 도시 이름 알아내기
-
오프라인에서 할려면?
-
왜냐? 네트웍 안쓰고 하려니까...
-
https://github.com/thampiman/reverse-geocoder/tree/master/reverse_geocoder (csv가 부족)
-
https://github.com/daveross/offline-country-reverse-geocoder
-
미리 만들어진 테이블을 이용해서 가장 가까운 gps 좌표를 찾는 방식
-
실패할때만 online geocoder 를 사용하는 식으로 처리 하는 것도 좋을 듯
online geocoder - CLLocation 은 네트웍을 사용한다.
- https://developer.apple.com/documentation/corelocation/clgeocoder
- https://developer.apple.com/documentation/corelocation/converting_between_coordinates_and_user-friendly_place_names
To use a geocoder object, you create it and call one of its forward- or reverse-geocoding methods to begin the request. Reverse-geocoding requests take a latitude and longitude value and find a user-readable address. Forward-geocoding requests take a user-readable address and find the corresponding latitude and longitude value.
주소 -> gps 좌표 (geocoder)
import CoreLocation
var geocoder = CLGeocoder()
geocoder.geocodeAddressString("your address") {
placemarks, error in
let placemark = placemarks?.first
let lat = placemark?.location?.coordinate.latitude
let lon = placemark?.location?.coordinate.longitude
print("Lat: \(lat), Lon: \(lon)")
}
gps 좌표 -> 주소 (reverse geocoder)
func lookUpCurrentLocation(completionHandler: @escaping (CLPlacemark?)
-> Void ) {
// Use the last reported location.
if let lastLocation = self.locationManager.location {
let geocoder = CLGeocoder()
// Look up the location and pass it to the completion handler
geocoder.reverseGeocodeLocation(lastLocation,
completionHandler: { (placemarks, error) in
if error == nil {
let firstLocation = placemarks?[0]
completionHandler(firstLocation)
}
else {
// An error occurred during geocoding.
completionHandler(nil)
}
})
}
else {
// No location was available.
completionHandler(nil)
}
}