Хотите получить название штата из почтового индекса - PullRequest
3 голосов
/ 12 марта 2012

Я делаю приложение для iphone с полем почтового индекса.Когда пользователь вводит почтовый индекс, я хочу получить название штата из почтового индекса. Может ли кто-нибудь подсказать мне.

Ответы [ 3 ]

3 голосов
/ 12 марта 2012

Для этого вы можете использовать API геокодирования

http://maps.googleapis.com/maps/api/geocode/json?address=77048&sensor=true

где адрес - ваш почтовый индекс. Здесь вы можете увидеть для API геокодирования.

3 голосов
/ 12 марта 2012

Вы можете использовать Yahoo API как:

 http://where.yahooapis.com/geocode?q=77048&appid=0

, где q = zipCode

1 голос
/ 27 марта 2012

Привет, наконец, я сделал с помощью Google Api. Кроме того, после того, как вытащил мои волосы в течение длительного времени, есть решение для этого.

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;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...