获取经纬度

//

//ViewController.m

//A01_获取当前位置(定位)

//

//Created by apple on 15/6/27.

//Copyright (c) 2015年itcast. All rights reserved.

//

#import"ViewController.h"

#import

@interfaceViewController()

@property(nonatomic,strong)CLLocationManager* manager;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{

//获取当前的位置,使用CLLocationManager对象

CLLocationManager*manager = [[CLLocationManageralloc]init];

//当要使用的时候,请求授权

#warning requestWhenInUseAuthorization的方法,只能在8.0以上系统调用

if([[UIDevicecurrentDevice].systemVersiondoubleValue] >=8.0) {

[managerrequestWhenInUseAuthorization];

}

////不管三七二十一,直接请求授权

//[manager requestAlwaysAuthorization];

//设置代理

manager.delegate=self;

//每一百米定位一次-内部还是时时定位,只是过一百米后,调用代理方法

manager.distanceFilter=100;

//定位的时候,设置误差精确度在10米范围内,精确度越高,比较耗性能

manager.desiredAccuracy=10;

//开启定位(时时定位)

[managerstartUpdatingLocation];

self.manager= manager;

}

#pragma mark获取定位位置信息

-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations{

//CLLocation位置对象

for(CLLocation*locinlocations) {

NSLog(@"当前位置的经纬度经度:%lf纬度:%lf行走速度%lf",loc.coordinate.longitude,loc.coordinate.latitude,loc.speed);

}

//一旦定位到信息,马上停止定位

//[manager stopUpdatingLocation];

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容