I am attempting to reverse geocode a user's location in iOS 13. I am getting results as expected with the exception of the thoroughfare property.
Regrardless of the location I pick everything works as expected except this one property not returning results. Subthoroughfare returns a value when one is available which I would expect to sometimes be nil. I get the same results regardless of simulator or on device.
Has anyone experienced something like this? Other than I need to clean up my prototype code do you see anything I am doing incorrectly?
In my Geocoding function (snippet for brevity):
func geocode(
location: CLLocation,
completionHander: @escaping (CLPlacemark?) -> Void)
{
... //some rate limiting stuff..
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemark, error) in
if error == nil {
let firstLocation = placemark?.first
completionHander(firstLocation)
}else{
completionHander(nil)
}
}
When I require a new location:
geocode(location: lastLocation) { placemark in
if let place = placemark {
let name = place.name
let thoroughfare = place.thoroughfare
let subthoroughfare = place.subThoroughfare
let locality = place.locality
let country = place.country
print("name: \(name), thoroughfare: \(thoroughfare), subthoroughfare: \(subthoroughfare), locality: \(locality), country: \(country)")
if let street = place.thoroughfare {
print("throughfare: \(street)")
} else{
print("name: \(place.name!)")
}
} else {
print("no place found")
}
}
Results Examples:
As mentioned I am getting the same results on device from multiple locations here in Canada, but I don't want to share my address with everyone 😉
Expect throughfare to be populated:
name: Optional("Apple Campus"), throughfare: nil, subthroughfare: Optional("1"), locality: Optional("Cupertino"), country: Optional("United States")
name: Optional("Sam H. Lawson Middle School"), thoroughfare: nil, subthoroughfare: Optional("10401"), locality: Optional("Cupertino"), country: Optional("United States")
name: Optional("10889 N De Anza Blvd"), thoroughfare: nil, subthoroughfare: Optional("10889"), locality: Optional("Cupertino"), country: Optional("United States")
Expect throughfare and subthroughfare would be empty:
name: Optional("Elbow - Sheep Wildland Provincial Park"), thoroughfare: nil, subthoroughfare: nil, locality: nil, country: Optional("Canada")
name: Optional("I-280 N"), thoroughfare: nil, subthoroughfare: nil, locality: Optional("Cupertino"), country: Optional("United States")
Thanks in advance for any assistance.