Ich versuche, Adresse über CLLocationManager mit Breiten- und Längengrad zu bekommen, aber es gibt nur Staat und Land Name, ich will Stadt auch, ich bin meinen Code anhängen kann mir jemand sagen, wie kann ich meinen Code ändern, um Stadt Namen auch zu bekommen. unten ist mein CodeWie erhält man den Städtenamen über CLlocationManager mit Längen- und Breitengrad in IOS?
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
CLGeocoder *geocoder1 = [[CLGeocoder alloc] init];
NSLog(@"Detected Location : %f, %f", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
//CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:26.9260 longitude:75.8235];
CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
[geocoder1 reverseGeocodeLocation:newLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(@"Geocode failed with error: %@", error);
return;
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *placemark = placemarks[0];
NSDictionary *addressDictionary =
placemark.addressDictionary;
NSLog(@"%@ ", addressDictionary);
NSString *address = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStreetKey];
NSString *city = [addressDictionary
objectForKey:(NSString *)kABPersonAddressCityKey];
NSString *state = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStateKey];
NSString *zip = [addressDictionary
objectForKey:(NSString *)kABPersonAddressZIPKey];
NSLog(@"%@ %@ %@ %@", address,city, state, zip);
}
}];
}
Sie erhalten nicht wirklich "Adresse über CLLocationManager". Sie erhalten es über CLGeocoder (CLLocationManager gibt Ihnen nur Koordinaten). Der Code sieht gut aus. Es kann spezifisch für die Koordinaten sein, die CLGeocoder (Apple) möglicherweise nicht gut geokodieren kann (Google scheint darin besser zu sein). Sind die Koordinaten 26.9260, 75.8235? – Anna