Hogyan állapítható meg egy CLLocation vagy MKPlacemark címről?

szavazat
2

Láttam API dokumentációt és demo után demo, hogyan kell csinálni a fordított geokód - kap egy címet, egy Lat / Long helyét. Azt kell tennie, hogy a fordított. Feltételezem, hogy ez már megoldott probléma, mivel az Apple MapKit API kerüli meg teljesen.

A kérdést 20/09/2009 20:25
a forrás felhasználó
Más nyelveken...                            


1 válasz

szavazat
6

Ennek egyik módja, hogy használja a google webszolgáltatás így:

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

}
Válaszolt 20/09/2009 20:30
a forrás felhasználó

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