• 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"]);

            }

        }];

    }

  • 相关阅读:
    bootstrap图片上传功能
    Microsoft.EntityFrameworkCore.Sqlite的学习
    问题(待完成):微服务,失败回滚?保持事务的原子性?多步骤调用,如何来实现
    c# 重试机制
    .net core 问题:413 Request Entity Too Large nginx
    Validation
    Tag Helpers in forms in ASP.NET Core
    C/C++中如何获取数组的长度(宏&模板)
    斐波那契数列的实现
    PAT (Basic Level) Practise
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/4959696.html
Copyright © 2020-2023  润新知