系统定位
2016-02-15 09:57
316 查看
#import
"ViewController.h"
#import
<CoreLocation/CoreLocation.h>
@interface
ViewController
()<CLLocationManagerDelegate>
@property
(nonatomic
,retain)
CLLocationManager
*manger;
@end
@implementation
ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/**
定位
- returns:
*/
self.manger
= [[CLLocationManager
alloc]
init];
self.manger.delegate
=
self;
//距离刷新
self.manger.distanceFilter
=
10;
//定位精度
self.manger.desiredAccuracy
=
kCLLocationAccuracyBestForNavigation;
//开始定位
[self.manger
startUpdatingLocation];
//设置什么时候开始定位
//程序只要运行就会定位
[self.manger
requestAlwaysAuthorization];
//程序运行就会定位
[self.manger
requestWhenInUseAuthorization];
//计算经纬度之间的距离
[self
countdistance];
}
-(void)countdistance{
CLLocation *location = [[CLLocation
alloc]
initWithLatitude:23.3
longitude:113.33];
CLLocation *locationEnd = [[CLLocation
alloc]
initWithLatitude:40.60
longitude:117.78];
//计算距离调用方法
CLLocationDistance distance = [location
distanceFromLocation:locationEnd];
NSLog(@"distance ======= %f",distance);
}
-(void)locationManager:(CLLocationManager
*)manager didUpdateLocations:(NSArray<CLLocation
*> *)locations{
//获取用户位置的对象
CLLocation *location = [locations
lastObject];
CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"经度:
%f,
纬度: %f",coordinate.latitude,coordinate.longitude);
//停止定位
[self.manger
stopUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
"ViewController.h"
#import
<CoreLocation/CoreLocation.h>
@interface
ViewController
()<CLLocationManagerDelegate>
@property
(nonatomic
,retain)
CLLocationManager
*manger;
@end
@implementation
ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/**
定位
- returns:
*/
self.manger
= [[CLLocationManager
alloc]
init];
self.manger.delegate
=
self;
//距离刷新
self.manger.distanceFilter
=
10;
//定位精度
self.manger.desiredAccuracy
=
kCLLocationAccuracyBestForNavigation;
//开始定位
[self.manger
startUpdatingLocation];
//设置什么时候开始定位
//程序只要运行就会定位
[self.manger
requestAlwaysAuthorization];
//程序运行就会定位
[self.manger
requestWhenInUseAuthorization];
//计算经纬度之间的距离
[self
countdistance];
}
-(void)countdistance{
CLLocation *location = [[CLLocation
alloc]
initWithLatitude:23.3
longitude:113.33];
CLLocation *locationEnd = [[CLLocation
alloc]
initWithLatitude:40.60
longitude:117.78];
//计算距离调用方法
CLLocationDistance distance = [location
distanceFromLocation:locationEnd];
NSLog(@"distance ======= %f",distance);
}
-(void)locationManager:(CLLocationManager
*)manager didUpdateLocations:(NSArray<CLLocation
*> *)locations{
//获取用户位置的对象
CLLocation *location = [locations
lastObject];
CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"经度:
%f,
纬度: %f",coordinate.latitude,coordinate.longitude);
//停止定位
[self.manger
stopUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- iOS的几种设计模式
- iOS沙盒目录结构解析
- 将ios程序运行中的异常发送到指定邮箱
- ios输入的数字如果前面有0,保留去掉0之后的数据
- iOS开发学习之简单动画
- iOS9 中关闭ATS的方法
- iOS9 中关闭ATS的方法
- iOS9 中关闭ATS的方法
- 实例解析iOS应用多线程开发中NSthread类的用法
- iOS7中的ViewController切换
- iOS 学习资料整理{非要有用,强烈推荐}
- IOS开发基础篇--CAShapeLayer的strokeStart和strokeEnd属性
- iOS 字符属性NSAttributedString描述
- iOS显示“此证书的签发者无效”来破
- iOS 学习资料整理 {非常有用,强烈推荐}
- iOS 开发小记 (八)
- iOS ViewController生命周期
- 简单完美的解决键盘遮挡输入框的问题
- 蓝懿IOS多线程管理进程间访问
- iOS内存管理