系统定位

来源:互联网 发布:navicat for mysql安卓 编辑:程序博客网 时间:2024/04/27 22:49
#import"ViewController.h"
#import
<CoreLocation/CoreLocation.h>



@interfaceViewController()<CLLocationManagerDelegate>

@property(nonatomic,retain)CLLocationManager*manger;

@end

@implementationViewController

- (
void)viewDidLoad {
    [
superviewDidLoad];
   
// Do any additional setup after loading the view, typically from a nib.
   
/**
    
定位
    
     - returns:
     */

   
   
self.manger= [[CLLocationManageralloc]init];
   
self.manger.delegate= self;
   
//距离刷新
   
self.manger.distanceFilter= 10;
   
//定位精度
   
self.manger.desiredAccuracy= kCLLocationAccuracyBestForNavigation;
   
//开始定位
    [
self.mangerstartUpdatingLocation];
   
//设置什么时候开始定位
   
//程序只要运行就会定位
    [
self.mangerrequestAlwaysAuthorization];
   
//程序运行就会定位
    [
self.mangerrequestWhenInUseAuthorization];
   
//计算经纬度之间的距离
    [
selfcountdistance];
   
   
   
   
   
}

-(
void)countdistance{
   
CLLocation *location = [[CLLocationalloc]initWithLatitude:23.3longitude:113.33];
   
CLLocation *locationEnd = [[CLLocationalloc]initWithLatitude:40.60longitude:117.78];
   
//计算距离调用方法
   
CLLocationDistance distance  = [locationdistanceFromLocation:locationEnd];
   
NSLog(@"distance =======  %f",distance);
   
   
   
   
   
}

-(
void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray<CLLocation*> *)locations{
   
   
//获取用户位置的对象
   
CLLocation *location = [locationslastObject];
   
CLLocationCoordinate2D coordinate = location.coordinate;
   
NSLog(@"经度: %f, 纬度: %f",coordinate.latitude,coordinate.longitude);
   
//停止定位
    [
self.mangerstopUpdatingLocation];
   
}

- (
void)didReceiveMemoryWarning {
    [
superdidReceiveMemoryWarning];
   
// Dispose of any resources that can be recreated.
}

@end
0 0
原创粉丝点击