zoukankan      html  css  js  c++  java
  • 获取经纬度

    //1.导入头文件
    #import <CoreLocation/CoreLocation.h>
    //2.设置代理CLLocationManagerDelegate
    @interface ShopMyInfoViewController ()<CLLocationManagerDelegate>
    //3.viewDidLoad中调用getJingWeiDu方法
    //4、自动调代理方法 locationManager
    // 经纬度
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        NSLog(@"经度%f,纬度%f",newLocation.coordinate.longitude, newLocation.coordinate.latitude);
        [[UserModel sharedInstanced]setlongitude:[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude]];
        [[UserModel sharedInstanced]setlatitude:[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude]];
        //一直定位
        [manager stopUpdatingLocation];
    }
    - (void)getJingWeiDu{
        self.locationManager=[[CLLocationManager alloc]init];
        //期望精度
        self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        //大约变化10米更新一次
        //    self.locationManager.distanceFilter=10;
        //认证NSLocationAlwaysUsageDescription
        if([[UIDevice currentDevice] systemVersion].doubleValue>8.0)//如果ios是8.0以上版本
        {
            if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])//位置管理对象中有requestAlwaysAuthorization这个行为
            {
                //运行
                [self.locationManager requestAlwaysAuthorization];
            }
        }
        
        self.locationManager.delegate=self;
        [self.locationManager startUpdatingLocation];
    }
  • 相关阅读:
    卤菜技巧
    JS实现延迟
    软件项目版本号的命名规则及格式
    EF复合主键
    验证码和验证控件
    还原数据库,数据库提示正在还原中的处理办法
    更新汇总行
    centOS7挂在windows移动硬盘方法
    关于this、Echarts中的data
    SQLServer 查看SQL语句的执行时间
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7885607.html
Copyright © 2011-2022 走看看