Reputation: 8856
I'm trying to covert the address to respected latitude and longitude values i.e Geocoding.
From Google definition:
What is Geocoding?
Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map.
I am trying the same in iOS using Swift.
My code is working fine. But some addresses are not converting into lat, lng values. I am sure the address I'm searching is 100% valid.
Here is my code
override func viewDidLoad() {
super.viewDidLoad()
var address = "Kloten Airport, Switzerland" // This Address not working
var geocoder = CLGeocoder()
geocoder.geocodeAddressString(address, {(placemarks: [AnyObject]!, error: NSError!) -> Void in
if let placemark = placemarks?[0] as? CLPlacemark {
let title = ABCreateStringWithAddressDictionary(placemark.addressDictionary, false)
println(title);
let location = CLLocationCoordinate2D(
latitude: placemark.location.coordinate.latitude,
longitude: placemark.location.coordinate.longitude
)
}
})
}
I tried different addresses to geocode like Houston USA
(this worked well), "Rautistrasse 12" (this also worked well), but when I search the address Kloten Airport, Switzerland
this not worked for me.
Is there any bug, in iOS geocodeAddressString
, or something I'm doing wrong?
Upvotes: 1
Views: 4253
Reputation: 11073
I think you are expecting the iOS geocoding to perform as well as Google's geocoding. It certainly won't, though.
It is not working because Apple's geocoding is not as good as Google's geocoding.
To see what I mean, put
Kloten Airport, Sweden
into the iOS Maps app. It gives nothing. Put it into maps.google.com and you see the airport.
Upvotes: 6