• 获取经纬度


    //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];
    }
  • 相关阅读:
    Ubuntu安装GTK+教程
    Qt 错误GL/gl.h: No such file or directory的解决方法
    Qt 解决Could not start process "make" qmake_all问题
    Feign解决服务之间调用传递token
    python闭包和装饰器
    python高阶函数
    ping 和 traceroute 的区别
    ICMP协议
    OSPF协议
    RIP协议
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7885607.html
Copyright © 2020-2023  润新知