自带定位调用 地理编码 反地理编码

  • 自带的定位,地理编码,反地理编码进行了封装 SNLocation
  • 定位的配置 plist文件
1
2
3
4
5
#warning plist文件中添加
/*
 * NSLocationAlwaysUsageDescription String 应用程序始终使用定位服务
 * NSLocationWhenInUseUsageDescription String 使用应用程序期间,可以使用定位服务
 */
  • 简单的代码说明
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    CLLocationManager//定位管理
    desiredAccuracy //精度
    distanceFilter //更新距离;
    [CLLocationManager locationServicesEnabled];//检测定位是否可用
    //设置代理 以下是代理方法
    #pragma mark - 状态改变时调用
    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
    #pragma mark - 定位结果
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
    //地理编码
    CLGeocoder * geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
    }];
    //反地理编码
    CLGeocoder * geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
    }];
文章目录
|