Why does CLGeocoder reverseGeocodeLocation return a label with a different lat / long when it looks at the address?
Reference Information. As for the user, a “long press” on the map to remove the pin, but my code will reverse geocode to be able to name the area name on the Pin, but then the reset PIN is in a different place (i.e. not a very good user interface ) Therefore, I am looking for a way to use lat / long selected by the user, but then just find the location name.
Example: with the code below I see:
- Entrance: -28.7780218895614, 152.978574011267
- EXIT: -28.864405, 153.0001191
the code:
import UIKit
import CoreLocation
import PlaygroundSupport
let locInput = CLLocation(latitude: -28.778021889561444, longitude: 152.97857401126666)
print("Input: \(locInput.coordinate.latitude), \(locInput.coordinate.longitude)")
let geocoder: CLGeocoder = CLGeocoder()
print("About to call reverse geocoding function")
geocoder.reverseGeocodeLocation(locInput) { placemarks, error in
guard let placemarks = placemarks else {fatalError("No Placemarks Provided \(error?.localizedDescription)")}
for p in placemarks {
print("OUTPUT: \(p.location!.coordinate.latitude), \(p.location!.coordinate.longitude)")
}
}
PlaygroundPage.current.needsIndefiniteExecution = true