iOS 在8.0下如何获取当前位置的精度和纬度
来源:互联网 发布:金融行业大数据分析 编辑:程序博客网 时间:2024/06/04 01:03
iOS 8.0 下,苹果地图定位功能发生了部分改变。要想获取用户的当前位置的经纬度要做到:
1.在你的Supporting Files 中的 info.plist 文件中应该增加以下两项:
– ADD two new keys of Type STRING to the Info.plist of your project:
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
2.在viewDidLoad()方法中
{
_manager = [[CLLocationManageralloc]init];
_manager.delegate =self;
_manager.desiredAccuracy =kCLLocationAccuracyBest;
_manager.distanceFilter =kCLDistanceFilterNone;
[_managerrequestWhenInUseAuthorization];
if ([CLLocationManagerlocationServicesEnabled]) {
[_managerstartUpdatingLocation];
}
}
3.实现代理方法,获取用户的最新位置:
#pragma mark - LocationManager Delegate Method
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// locations 中存放的是用户当前位置的最新更新
CLLocation *location = [locationslastObject];
_userlatitude = [NSStringstringWithFormat:@"%f",location.coordinate.latitude];
_userlongitude = [NSStringstringWithFormat:@"%f",location.coordinate.longitude];
NSLog(@"地理位置:%@%@",_userlongitude,_userlatitude);
[_managerstopUpdatingLocation];
}
// 位置更新失败
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"位置更新error:%@",error);
}
4.在测试时 如果使用的模拟器则要要将位置更改为 中国香港之后就可以获取用户当前位置的经纬度了。
ios7.0 适配处理
if([_manager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_managerrequestAlwaysAuthorization]; // 永久授权
[_managerrequestWhenInUseAuthorization]; //使用中授权
}
- iOS 在8.0下如何获取当前位置的精度和纬度
- android 获取当前位置坐标 经度 纬度
- HTML 5取得用户的精度和纬度
- 百度地图之精度和纬度的相互转换
- Html5+如何获取ios手机当前位置
- GPS获取当前的经度和纬度
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- Android 获取地理位置的经度和纬度
- android 使用LocationClient获取精度,纬度坐标
- android 使用LocationClient获取精度,纬度坐标
- ios 利用自带的CoreLocation.framework 实现获取手机当前处于的精度和纬度 并计算两点之间的间距(特别使用于团购,附近商户之类的项目)
- IE和FF下获取鼠标当前位置
- iOS获取当前位置信息
- iOS---获取当前位置信息
- IOS获取当前位置
- IOS获取当前位置
- iOS获取当前位置经纬度
- 大数据技术贴:构建一个有指导的数据挖掘模型
- Chrome DEBUG network 的Timing说明
- Unity3D研究院之Assetbundle的原理(六十一)
- ws_test练习,spring、hibernate、jax-ws2.1的webservice
- 成为开源编程高手的11个技巧
- iOS 在8.0下如何获取当前位置的精度和纬度
- SQL语句例题
- MongoDB入门教程之Windows下的MongoDB数据库安装图解
- MFC 全局配置 读取保存配置
- ACM-欧拉函数
- 07 JS元素操作
- 语句std::cout<<std::endl的作用
- 手把手教你使用Git
- C#生成中文验证码