(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)
}
}