2
votes

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?

3
Possible to use googlel api ? Check this - Janak Nirmal

3 Answers

9
votes

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.

0
votes

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

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

-1
votes

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 .