ios8 CLLocationManager开发笔记一 定位
来源:互联网 发布:关系型数据库设计 编辑:程序博客网 时间:2024/06/16 16:23
- (void)viewDidLoad
{
[superviewDidLoad];
locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate =self;
self.locationManager.desiredAccuracy =kCLLocationAccuracyBest;//指定需要的精度级别
self.locationManager.distanceFilter =1000.0f;//设置距离筛选器
// 用于获取plist 里内容,如何不添加此函数很悲剧,不会走delegate 的
if ([self.locationManagerrespondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManagerrequestWhenInUseAuthorization];
}
[self.locationManagerstartUpdatingLocation];//启动位置管理器
}
在plist 里添加下面字段,可以用来描述定位通途
NSLocationWhenInUseUsageDescription
#pragma mark -- 获取经纬度Delegate
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//纬度
NSString * latitudeString = [NSStringstringWithFormat:@"%f",newLocation.coordinate.latitude];
NSLog(@"xx%@",latitudeString);
//精度
NSString * longitudeString = [NSStringstringWithFormat:@"%f",newLocation.coordinate.longitude];
NSLog(@"yy%@",longitudeString);
//海拔
NSString * horizontalAccuracyString = [NSStringstringWithFormat:@"%gm",newLocation.horizontalAccuracy];
NSLog(@"hh%@",horizontalAccuracyString);
CLGeocoder *geocoder = [[CLGeocoderalloc]init];
[geocoder reverseGeocodeLocation: newLocationcompletionHandler:^(NSArray *placemarks,NSError *error) {
if (!error) {
for (CLPlacemark *placemarkin placemarks)
{
// @property (nonatomic, readonly) NSString *name; // eg. Apple Inc.
// @property (nonatomic, readonly) NSString *thoroughfare; // street address, eg. 1 Infinite Loop
// @property (nonatomic, readonly) NSString *subThoroughfare; // eg. 1
// @property (nonatomic, readonly) NSString *locality; // city, eg. Cupertino
// @property (nonatomic, readonly) NSString *subLocality; // neighborhood, common name, eg. Mission District
// @property (nonatomic, readonly) NSString *administrativeArea; // state, eg. CA
// @property (nonatomic, readonly) NSString *subAdministrativeArea; // county, eg. Santa Clara
// @property (nonatomic, readonly) NSString *postalCode; // zip code, eg. 95014
// @property (nonatomic, readonly) NSString *ISOcountryCode; // eg. US
// @property (nonatomic, readonly) NSString *country; // eg. United States
// @property (nonatomic, readonly) NSString *inlandWater; // eg. Lake Tahoe
// @property (nonatomic, readonly) NSString *ocean; // eg. Pacific Ocean
// @property (nonatomic, readonly) NSArray *areasOfInterest; // eg. Golden Gate Park
// @end
_countryLabel.text = [placemarkcountry]; //哪个国家
_provinciaLabel.text = [placemark administrativeArea];
_cityLabel.text = [placemarklocality]; //哪个城市
_subLocalityLabel.text = [placemark subLocality];//哪个区
_streetLabel.text = [placemarkthoroughfare]; //哪个街道
NSLog(@"%@", [[placemarkaddressDictionary]description]);
}
}
else
{
NSLog(@"There was a reverse geocoding error\n%@",
[error localizedDescription]);
}
}
];
_latitudeLabel.text = latitudeString;
_longitudeLabel.text = longitudeString;
_elevationLabel.text = horizontalAccuracyString;
}
#pragma mark -- 获取经纬度失败delegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"locError:%@", error);
}
-(void)dealloc
{
self.locationManager.delegate =nil;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- ios8 CLLocationManager开发笔记一 定位
- ios8 CLLocationManager开发笔记一 定位
- iOS CLLocationManager定位,IOS8注意
- IOS8无法启用定位的服务:CLLocationManager
- ios8 CLLOcationManager 定位与ios7的对比
- IOS:ios8.0下CLLocationManager定位服务
- IOS8 使用CLLocationManager定位服务问题
- ios8之后使用CLLocationManager进行定位
- Ios开发之定位CLLocationManager
- iOS开发之定位CLLocationManager
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- ios8.0下CLLocationManager定位服务需要授权了
- 反渗透设备:反渗透设备技术特点详细解析
- 博弈-1
- 查找目录下的所有文件中是否含有某个字符串 linux
- 【编程之美】1.2中国象棋的将帅问题
- SQLyog数据库创建
- ios8 CLLocationManager开发笔记一 定位
- 数据结构 && ACM :比较两棵树是否相等。
- Java程序员应该知道的10个调试技巧
- Xcode插件失效的问题
- 第11题:移除数组中的重复元素
- SVN版冲突解决方法
- 在ORACLE中输入DATE类型的字段
- iOS原生地图
- shell基础二十篇