The simplest way is to upgrade to Version 1.7 of the Google Maps SDK for iOS (released February 2014).
From the release notes:
GMSGeocoder
now provides structured addresses viaGMSAddress
, deprecatingGMSReverseGeocodeResult
.
From GMSAddress
Class Reference, you can find these properties:
coordinate
Location, orkLocationCoordinate2DInvalid
if unknown.
thoroughfare
Street number and name.
locality
Locality or city.
subLocality
Subdivision of locality, district or park.
administrativeArea
Region/State/Administrative area.
postalCode
Postal/Zip code.
country
The country name.
lines
An array ofNSString
containing formatted lines of the address.
No ISO country code though.
Also note that some properties may return nil
.
Here's a full example:
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(40.4375, -3.6818) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) {
NSLog(@"reverse geocoding results:");
for(GMSAddress* addressObj in [response results])
{
NSLog(@"coordinate.latitude=%f", addressObj.coordinate.latitude);
NSLog(@"coordinate.longitude=%f", addressObj.coordinate.longitude);
NSLog(@"thoroughfare=%@", addressObj.thoroughfare);
NSLog(@"locality=%@", addressObj.locality);
NSLog(@"subLocality=%@", addressObj.subLocality);
NSLog(@"administrativeArea=%@", addressObj.administrativeArea);
NSLog(@"postalCode=%@", addressObj.postalCode);
NSLog(@"country=%@", addressObj.country);
NSLog(@"lines=%@", addressObj.lines);
}
}];
and its output:
coordinate.latitude=40.437500
coordinate.longitude=-3.681800
thoroughfare=(null)
locality=(null)
subLocality=(null)
administrativeArea=Community of Madrid
postalCode=(null)
country=Spain
lines=(
"",
"Community of Madrid, Spain"
)
Alternatively, you may consider using Reverse Geocoding in the The Google Geocoding API (example).