Вопрос

Я видел документацию по API и демонстрацию за демонстрацией того, как выполнить обратное геокодирование - чтобы получить адрес с учетом местоположения по широте и долготе.Мне нужно сделать обратное.Я предполагаю, что это уже решенная проблема, поскольку API MapKit от Apple полностью ее избегает.

Это было полезно?

Решение

Один из способов — использовать веб-сервис Google следующим образом:

-(CLLocationCoordinate2D) addressLocation {
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                           [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSLog(@"locationString = %@",locationString);

    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    double latitude = 0.0;
    double longitude = 0.0;
    if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
/*      
        NSString *nameString = [NSString stringWithFormat:@"http://ws.geonames.org/findNearestAddress?lat=%f&lng=%f",latitude,longitude];
        NSString *placeName = [NSString stringWithContentsOfURL:[NSURL URLWithString:nameString]];
        NSLog(@"placeName = %@",placeName);
 */
    }
    else {
        //Show error
    }
    CLLocationCoordinate2D location;
    location.latitude = latitude;
    location.longitude = longitude;

    return location;

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top