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];
    }
  • 相关阅读:
    day17 内置方法、数学模块、randrange随机模块、序列化模块pickle
    线性模型L2正则化——岭回归
    KMP算法
    KNN算法:KNN-classifier和KNN-regressor
    机器学习开篇——编译器的选择
    STL好坑
    树状数组学习笔记
    无题
    最小树形图:朱刘算法
    2019ICPC徐州站题解
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7885607.html
Copyright © 2011-2022 走看看