2

Im using Map Kit and Core Location now and need to to get location information from zip code or city/state. Is there any way to do it?

user1248568
  • 621
  • 1
  • 9
  • 29
  • Possible to use googlel api ? [Check this](http://stackoverflow.com/questions/4749706/lookup-city-and-state-by-zip-google-geocode-api) – Janak Nirmal Apr 12 '13 at 12:55

3 Answers3

9

You can use the CLGeocoder class which supports converting an address to a coordinate, and the reverse. For example:

[geocoder geocodeAddressString:@"<postcode here>"
             completionHandler:^(NSArray* placemarks, NSError* error){
                 for (CLPlacemark* aPlacemark in placemarks)
                 {
                     // Process the placemark.
                 }
}];

There are a bunch of different methods you may want to use. You can limit the search to a particular region, for example.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
0

You can use https://thezipcodes.com/ to get location from ZIP Code.

To integrate with your website follow http://thezipcodes.com/docs

nkkumawat
  • 693
  • 1
  • 6
  • 9
-1

Use this

-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) addressStr {

double latitude = 0, longitude = 0;
NSString *esc_addr =  [addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
if (result) {
    NSScanner *scanner = [NSScanner scannerWithString:result];
    if ([scanner scanUpToString:@"\"lat\" :" intoString:nil] && [scanner scanString:@"\"lat\" :" intoString:nil]) {
        [scanner scanDouble:&latitude];
        if ([scanner scanUpToString:@"\"lng\" :" intoString:nil] && [scanner scanString:@"\"lng\" :" intoString:nil]) {
            [scanner scanDouble:&longitude];
        }
    }
}
CLLocationCoordinate2D center;
center.latitude = latitude;
center.longitude = longitude;
return center;

}

This method returns Coordinates using google api when you pass address as argument in this .

Nishant Tyagi
  • 9,893
  • 3
  • 40
  • 61
  • 1
    That solution has a limitation of 2500 request per day, also the results has to be shown on a goolge maps so it is not valid for iOS6. – javienegas Jul 01 '13 at 09:11