1 2 3 4 5
| /* * 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];//检测定位是否可用 //设置代理 以下是代理方法 - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status - (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) { }];
|