iOS8环境下地图定位需要注意的地方
2014-10-15 16:06
211 查看
1.iOS8的定位服务需要用户取申请系统的授权
即需要在plist文件中增加两个string类型的键值对:NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription。同时在开始定位之前必须调用申请授权的方法:
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
[locationManager
requestWhenInUseAuthorization];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
requestAlwaysAuthorization和requestWhenInUseAuthorization两个方法即是在申请系统的授权。
2.实机运行时记得要在系统设置中打开手机的定位服务,如果时模拟器的话除了打开模拟器设置中的定位服务外还需要在edit
schema 中设置模拟器的默认位置。
3.如果进入了失败的委托方法,可以根据error的code值从
CLError.h文件中查对应的原因
4.为稳妥起见,CLLocationManager的didChangeAuthorizationStatus方法务必实现,代码如下
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case
kCLAuthorizationStatusNotDetermined:
if ([locationManager
respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager
requestAlwaysAuthorization];
}
break;
default:
break;
}
}
即需要在plist文件中增加两个string类型的键值对:NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription。同时在开始定位之前必须调用申请授权的方法:
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
[locationManager
requestWhenInUseAuthorization];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
requestAlwaysAuthorization和requestWhenInUseAuthorization两个方法即是在申请系统的授权。
2.实机运行时记得要在系统设置中打开手机的定位服务,如果时模拟器的话除了打开模拟器设置中的定位服务外还需要在edit
schema 中设置模拟器的默认位置。
3.如果进入了失败的委托方法,可以根据error的code值从
CLError.h文件中查对应的原因
4.为稳妥起见,CLLocationManager的didChangeAuthorizationStatus方法务必实现,代码如下
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case
kCLAuthorizationStatusNotDetermined:
if ([locationManager
respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager
requestAlwaysAuthorization];
}
break;
default:
break;
}
}
相关文章推荐
- win7下搭建android环境 几个需要注意的地方
- node.js express环境下中文需要注意的地方
- ios8版本地图定位注意点
- NBMA环境下OSPF配置需要注意的地方
- 集群环境下开发需要注意哪些地方?
- IIS+PHP+MySQL环境中PHP.INI需要注意的几个地方
- 阿里云学生机ubuntu搭建mysql开启3306,80,8080端口环境需要注意的地方
- SVN 环境搭建 需要注意的地方
- sharepoint环境安装过程中几点需要注意的地方
- 考試時需要注意的地方
- Bulk collect的一个需要注意的地方
- 牛人就是很牛,人家说他牛,注意看,一定有你需要学习的地方
- 使用Java中的final变量需要注意的地方。
- 使用Java中的final变量需要注意的地方。
- Asp程序员转Asp.net程序员需要注意的地方
- 实现自定义page基类时需要注意的地方
- vc编写全局钩子需要注意的一个地方
- Operator= 需要注意的地方
- ClickOnce 部署多语言程序需要注意的地方
- 在ascx中使用js做验证时需要注意的小地方.