iOS 在8.0下如何获取当前位置的精度和纬度
2014-11-05 12:11
309 查看
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)]) {
[_manager
requestAlwaysAuthorization]; //
永久授权
[_manager
requestWhenInUseAuthorization]; //使用中授权
}
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)]) {
[_manager
requestAlwaysAuthorization]; //
永久授权
[_manager
requestWhenInUseAuthorization]; //使用中授权
}
相关文章推荐
- ios 利用自带的CoreLocation.framework 实现获取手机当前处于的精度和纬度 并计算两点之间的间距(特别使用于团购,附近商户之类的项目)
- 如何使用Core Location获取当前的位置和GPS的坐标呢?
- VC中如何获取当前时间(精度达到毫秒级)
- 如何获取用户手机当前是否启动了android机的模拟位置功能
- IOS获取当前位置
- iOS利用CoreLocation获取地理位置以及如何在模拟器进行调试
- iOS定位操作,获取当前位置,计算两点之间距离
- iOS---获取当前位置信息
- iOS利用CoreLocation获取地理位置以及如何在模拟器进行调试
- iOS如何获取手机当前的网络状态
- iOS获取当前位置信息
- 在iOS开发中自动获取当前的位置(GPS定位)
- iOS定位操作,获取当前位置,计算两点之间距离
- IOS获取当前地理位置文本
- 如何获取当前 CDocument 或 CView 从任意位置
- delphi如何获取鼠标当前位置颜色
- ios 定位获取当前位置信息
- 如何在 Windows Phone 8 中获取手机的当前位置
- IOS获取当前地理位置文本
- IOS获取当前地理位置文本