zoukankan      html  css  js  c++  java
  • 根据经纬度反向地理编译出地址信息(如果报错: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);
            }
        }];
    }
  • 相关阅读:
    NGINX 代理以及 HTTPS (一)
    HTTP 各种特性应用(二)
    HTTP 各种特性应用(一)
    HTTP 协议基础及发展历史
    添加 表格
    C# 利用反射和特性 来做一些事情
    HTTP 与 HTTPS
    系统登录详解
    js表单提交到后台对象接收
    idea插件
  • 原文地址:https://www.cnblogs.com/dujiahong/p/9923641.html
Copyright © 2011-2022 走看看