Wie kann ich ein CLLocation oder MKPlacemark von einer Adresse bestimmen?

stimmen
2

Ich habe API-Dokumentation gesehen und Demo nach Demo auf, wie eine umgekehrte Geocodierung zu tun - eine Adresse zu bekommen, da eine Breite / Länge Lage. Ich brauche das Gegenteil zu tun. Ich gehe davon aus, dass dies bereits Problem gelöst ist seit Apples MapKit API es vollständig vermeidet.

Veröffentlicht am 20/09/2009 um 20:25
quelle vom benutzer
In anderen Sprachen...                            


1 antworten

stimmen
6

Eine Möglichkeit ist das Google-Webservice zu verwenden, etwa so:

-(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;

}
Beantwortet am 20/09/2009 um 20:30
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more