I have an App that does forward geocoding (get coordinates given address) to display a bunch of pins on an MKMapView
. The app was developed well before iOS supported forward geocoding using CLGeocoder
(first available in iOS 5). As such my app uses the Google Maps Geocoding API, which is generally very accurate. Given a full address with a street number it will generally give you the exact location of that address within a couple of metres.
I'm doing some updates to my App to support iOS 6 and decided to switch from using the Google API to using CLGeocoder
provided the app was running on iOS 5 or above. However in my tests (all with addresses in Portugal, where I live) it is so inaccurate as to be totally unusable.
I'm using – geocodeAddressString:completionHandler:
and, for example, given the address "Avenida da Liberdade 195, Lisboa, Portugal" it gives me an "Avenida da Liberdade" in the city of Sintra, not Lisboa (Lisbon). That's about 15km away from the real address. Avenida da Liberdade is one of the biggest and most well known avenues in Lisbon. The equivalent of, say, 5th Avenue in NYC. It's not some obscure little side street.
Is there anything I'm doing wrong to get such terrible accuracy? Are others having similar accuracy issues, especially with addresses outside the US?
For the time being it looks like I'll have to stick with the Google Maps API. Incidentally, I've been using the iOS 6 simulator and there the results are no better. Putting the same search string into the search box on the iOS 6 Maps app gives the same totally inaccurate results.
EDIT: added CLGeocoder
code:
CLGeocoder *fgeo = [[[CLGeocoder alloc] init] autorelease];
NSLog(@"Geocoding for Address: %@\n", address);
[fgeo geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error) {
// do stuff with the placemarks
for (CLPlacemark *placemark in placemarks) {
NSLog(@"%@\n %.2f,%.2f",[placemark description], placemark.location.horizontalAccuracy, placemark.location.verticalAccuracy);
}
} else {
NSLog(@"Geocoding error: %@", [error localizedDescription]);
}
}];
EDIT 2: I've discovered that if I use – geocodeAddressDictionary:completionHandler:
and pass in an Address Dictionary with the street address, postal code (zip code) and as much detail as I can possibly provide, it gives me reasonably accurate coordinates, but still with an accuracy radius of more than 400m which is unacceptable.
Well, it would appear that yes, Apple's
CLGeocoder
is nothing like as accurate for forward geocoding (address -> coordinates) as the Google Maps Geocoding API, particularly outside of the USA. Using an Address Dictionary with all the fields filled out as fully as possible works a lot better than a simple address string, but it's still no where near good enough. Where Google will (usually) give you coordinates within 5-10m of the street number, Apple will give you coordinates somewhere in the right street, if you're lucky.EDIT: Found Apple Developer Technical Note TN2289 which details Supported Countries for
CLGeocoder
. It would appear that Portugal is in its list of Partially Supported Regions, which it describes as:Which matches my results with
CLGeocoder
in Portugal. I guess I'll just have to wait for improved coverage.