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];
    }
  • 相关阅读:
    将表中数据生成SQL语句
    遍历页面所有的控件
    MSN不能登陆
    刷新框架页
    JS传参出现乱码
    iframe攻击
    有关于VS调试Javascript的问题
    C#中StringBuilder类的使用
    前瞻XAML
    Asp.Net在SqlServer中的图片存取
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7885607.html
Copyright © 2011-2022 走看看