zoukankan      html  css  js  c++  java
  • iOS中城市定位功能的实现

    引入框架:CoreLocation


    .h文件

    引入CoreLocation/CoreLocation.h

    @interface WeatherViewController :UIViewController<</span>CLLocationManagerDelegate>{

        CLLocationManager* locationManager;

    }

    @property (strong, nonatomic) CLLocationManager* locationManager;

    @end

     
     
    .m文件

    //开始定位

    -(void)startLocation{

        self.locationManager = [[CLLocationManager alloc] init];

        self.locationManager.delegate = self;

        self.locationManager.desiredAccuracy =kCLLocationAccuracyBest;

        self.locationManager.distanceFilter = 10.0f;

        [self.locationManager startUpdatingLocation];

    }

    //定位代理经纬度回调

    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

        

        [locationManager stopUpdatingLocation];

        NSLog(@"location ok");

        NSLog(@"%@",[NSString stringWithFormat:@"经度:%3.5f 纬度:%3.5f",newLocation.coordinate.latitude,newLocation.coordinate.longitude]);

        

        CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

        [geoCoder reverseGeocodeLocation:newLocationcompletionHandler:^(NSArray *placemarks, NSError *error) {

            for (CLPlacemark * placemark in placemarks) {

                

                NSDictionary *test = [placemark addressDictionary];

                //  Country(国家)  State(城市)  SubLocality(区)

                NSLog(@"%@", [test objectForKey:@"State"]);

            }

        }];

    }

  • 相关阅读:
    hdu6514 // 二维差分 二维前缀和 基本容斥 压维
    【模板】欧拉函数 & 欧拉筛
    并查集模板 hdu1703
    大数 gcd
    hdu1087 dp
    洛谷p1306 斐波那契公约数
    hdu6814 Tetrahedron 线性求逆元 + 快速幂求逆元
    hdu6867 Tree // DFS
    hdu6869 Slime and Stones // 威佐夫博弈&#183;改
    Python实现EXCEL表格的排序功能
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/4959696.html
Copyright © 2011-2022 走看看