Ho visto la documentazione delle API e demo dopo demo su come fare un geocode inverso - per ottenere un indirizzo, data una / posizione lungo Lat. Ho bisogno di fare il contrario. Sto supponendo che questo è già risolto problema in quanto MapKit API di Apple evita del tutto.
Come è possibile determinare un CLLocation o MKPlacemark da un indirizzo?
voti
2
È pubblicato 20/09/2009 alle 20:25 2009-09-20 20:25
fonte dall'utente Greg Hurlman
In altre lingue...
fonte dall'utente Greg Hurlman
In altre lingue...
1 risposte
voti 6
6
Un modo è quello di utilizzare il webservice google in questo modo:
-(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;
}