Jak mohu určit CLLocation nebo MKPlacemark z adresy?

hlasů
2

Viděl jsem v dokumentaci API a demo po demo o tom, jak to udělat reverzní geocode - získat adresu, daný Lat / Long umístění. Musím udělat pravý opak. Jsem za předpokladu, že toto je již vyřešen problém, protože Apple MapKit API to vyhne úplně.

Položena 20/09/2009 v 20:25
zdroj uživatelem
V jiných jazycích...                            


1 odpovědí

hlasů
6

Jednou z možností je použít google webservice třeba takto:

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

}
Odpovězeno 20/09/2009 v 20:30
zdroj uživatelem

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