I am making an iphone application which has a zip code field. When the user enter the zip code I want to get the state name from zip code is it possible can any one suggest me.
You can use Yahoo's API like :
http://where.yahooapis.com/geocode?q=77048&appid=0
where q = zipCode
You can use Geocoding API for that like this
http://maps.googleapis.com/maps/api/geocode/json?address=77048&sensor=true
where address is your zipcode.You can see here for Geocoding API.
Hi finally i have done with the help of google api.Also after pulling my hair for a long time a got a solution to it.
str_StateName = @"";
NSString *address = [NSString stringWithFormat:@"United States,%@,%@",txt_City.text,txt_ZipCode.text];
NSString *urlString1 = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true",
[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSError *error = nil;
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString1] encoding:NSUTF8StringEncoding error:&error];
NSArray *listItems = [locationString componentsSeparatedByString:@"\""];
//NSArray *names = [listItems valueForKeyPath:@"long_name"];
for (i = 0; i < [listItems count]; i++)
{
if ([[listItems objectAtIndex:i] isEqualToString:@"administrative_area_level_1"])
{
NSLog(@"[listItems objectAtIndex:%d] %@",i,[listItems objectAtIndex:i-8]);
str_StateName = [NSString stringWithFormat:@"%@",[listItems objectAtIndex:i-8]];
}
}
if([str_StateName isEqualToString:@""])
{
alertView = [[ UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter correct zip code and city." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.