没有从纬度和经度获得地址

时间:2012-08-25 15:04:44

标签: iphone ios5

我使用以下代码从当前纬度和经度获取地址,但我无法得到正确的回复

- (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);
        }
    }];
}

1 个答案:

答案 0 :(得分:0)

CLLocation目前报道不佳;见this document。您可能正在尝试从覆盖不良的区域对地理位置进行地理编码。

如果是这种情况,还有其他地理编码器,例如Google's Geocoder(要求您在地图上显示结果)。