ios8 CLLocationManager开发笔记一 定位
来源:互联网 发布:阿里云tv遥控器 编辑:程序博客网 时间:2024/06/04 10:06
- (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定位服务需要授权了
- Ng机器学习课程Notes学习及编程实战系列-Part 2 Logistic Regression
- WebView加载Gif
- 学会换位思考,你的世界才会简单,人心简单就幸福
- 关于避免fragment重复加载
- 深入浅出pmp 读书笔记
- ios8 CLLocationManager开发笔记一 定位
- Java 内存分配全面浅析
- Android SQLite 支持嵌套事务吗?
- iOS7的适配
- Java 程序里的内存泄漏
- ios Map 开发笔记二 地图
- 眼球上的科技 隐形眼镜可以当电视看
- HttpContext.Current并非无处不在
- iOS推送:Java服务器端发送表情(绘文字)