zoukankan      html  css  js  c++  java
  • 获取手机当前经纬度的方法

    首先头文件应继承CLLocationManagerDelegate.
    并:#import <CoreLocation/CoreLocation.h>

    响应事件中写如下代码:
    CLLocationManager *_locManager = [[CLLocationManager alloc] init]; 
    [_locManager setDelegate:self]; 
    [_locManager setDesiredAccuracy:kCLLocationAccuracyBest];    
    [_locManager startUpdatingLocation];

    重载
    #pragma mark -
    #pragma mark Location manager
    - (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation
    {
        CLLocationCoordinate2D loc = [newLocation coordinate];
        NSString *lat =[NSString stringWithFormat:@"%f",loc.latitude];//get latitude
        NSString *lon =[NSString stringWithFormat:@"%f",loc.longitude];//get longitude    
        NSLog(@"%@ %@",lat,lon);
    }

  • 相关阅读:
    Python运算符及逻辑运算
    Python编码、流程控制、格式化输出
    Docker私有仓库Harbor部署与使用
    react
    理事会
    关于elementui form表单过长,看不到未填项
    js
    vue 父子传值
    养生
    html知识点
  • 原文地址:https://www.cnblogs.com/kelejiabing/p/4205762.html
Copyright © 2011-2022 走看看