【发布时间】:2012-08-25 15:04:43
【问题描述】:
我正在使用以下代码从当前纬度和经度获取地址,但我无法得到正确的响应
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
current_latitude=newLocation.coordinate.latitude;
current_longitude=newLocation.coordinate.longitude;
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if(placemarks && placemarks.count > 0)
{
CLPlacemark *placemark= [placemarks objectAtIndex:0];
NSString * address = [NSString stringWithFormat:@"%@ %@,%@ %@", [placemark subThoroughfare],[placemark thoroughfare],[placemark locality], [placemark administrativeArea]];
UIAlertView *art = [[UIAlertView alloc] initWithTitle:address message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[art show];
[art release];
NSLog(@"%@",address);
}
}];
}
【问题讨论】:
-
欢迎来到 SO,当你说你没有得到正确的回应时!我们不知道您会得到什么回应。所以请详细说明!告诉我们你期待什么,你得到了什么!你自己的代码会被破坏吗?
-
我在 [placemarks objectAtIndex:0]; 中获取数据,但是根据 doc,当我使用 [placemark locality] 获取数据时,我会得到空值。所有数据都来自 [placemarks objectAtIndex:0];这是正确的,但在使用 locality 时不正确。