Reputation: 863
How would you go about doing this? Does the iOS API offer any functions to retrieve a set of coordinates from a postal code?
The reverse geocoder gives me a postal code from a set a coordinates, but can I do it the other around?
Upvotes: 0
Views: 504
Reputation: 845
You can use Apple's CLGeocoder
class to forward geocode a string into a set of matching CLPlacemarks
, which will each include coordinate pairs for their locations. For example:
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"94107" completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Received placemarks: %@", placemarks);
}];
Or alternatively, you can try using the geocodeAddressDictionary:
method instead, which may yield more accurate/reliable results (though I haven't personally tested):
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
NSDictionary *locationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"94107", kABPersonAddressZIPKey, nil];
[geocoder geocodeAddressDictionary:locationDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Received placemarks: %@", placemarks);
}];
Upvotes: 2
Reputation: 2343
The iOS API only offers reverse geocoding at the moment means you can only get adress by CLLocation and not the other way around. If you'd like to do forward geocoding you should use google web api as you can read about here http://blog.sallarp.com/ipad-iphone-forward-geocoding-api-google/
Upvotes: 1