根据经纬度反向地理编译出地址信息(如果报错:Error Domain=kCLErrorDomain Code=8 "(null)")

注意:Error Domain=kCLErrorDomain Code=8 "(null)" 如果出现这个错误  一定是 经纬度有问题   一定是 经纬度有问题 一定是 经纬度有问题

- (void)reverseGeocoder{
    //创建地理编码对象
    CLGeocoder *geocoder=[[CLGeocoder alloc]init];
    //经度
    NSString *longitude = @"116.4582890000";
    //纬度
    NSString *latitude = @"39.9127500000";
    //创建位置
    CLLocation *location=[[CLLocation alloc]initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
    //根据经纬度反向地理编译出地址信息
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *array, NSError *error){
        if (array.count > 0){
            CLPlacemark *placemark = [array objectAtIndex:0];
            //获取城市
            NSString *city = placemark.locality;
            if (!city) {
                //四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
                city = placemark.administrativeArea;
            }
            NSLog(@"city = %@", city);//沈阳市
            NSLog(@"--%@",placemark.name);//黄河大道21号
            NSLog(@"++++%@",placemark.subLocality); //浑南区
            NSLog(@"country == %@",placemark.country);//中国
            NSLog(@"administrativeArea == %@",placemark.administrativeArea); //辽宁省
            NSString *addressStr = [NSString stringWithFormat:@"%@ %@ %@ %@",placemark.administrativeArea,city,placemark.subLocality,placemark.name];
            NSLog(@"administrativeArea == %@",addressStr);
        }
        else if (error == nil && [array count] == 0)
        {
            NSLog(@"No results were returned.");
        }
        else if (error != nil)
        {
            NSLog(@"An error occurred = %@", error);
        }
    }];
}
原文地址:https://www.cnblogs.com/dujiahong/p/9923641.html