iOS地图分析

在iOS8 以后地图的定位和以前不太一样 需要在Plist文件里添加

NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription

//导入头文件

#import <CoreLocation/CoreLocation.h>



  if (![CLLocationManager locationServicesEnabled])
       {
          
return;
       }
   
   
self.mgr= [[CLLocationManager alloc] init];
   
    [
self.mgr requestWhenInUseAuthorization];


      // 设置移动多少米,定位一次

        _mgr.distanceFilter = 50;

        

        // 设置定位精度

        _mgr.desiredAccuracy = kCLLocationAccuracyBest;

        

        // 设置CLLocationManager的代理,来获取用户的位置

        _mgr.delegate = self;





//代理方法 现实用户位置

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

{

    // 取出用户的位置信息

    CLLocation *location = [locations lastObject];

    

    CLLocationCoordinate2D coordinate = location.coordinate;

    

    NSLog(@"纬度:%f 经度:%f", coordinate.latitude, coordinate.longitude);

    //停止定位

    [manager stopUpdatingLocation];

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值