地理位置获取

定位:需要在info.plist中添加

NSLocationAlwaysUsageDescription 需要始终访问您的位置

NSLocationUsageDescription 需要访问您的位置

NSLocationWhenInUseUsageDescription 需要您的同意,在使用期间访问位置

NSLocationAlwaysAndWhenInUseUsageDescription 需要访问您的位置

项目添加框架CoreLocation.framework,并引入

#import <CoreLocation/CoreLocation.h>


-(void)startLocation {

         [[MapLocationManager shareInstance]startSystemLocationWithRes:^(CLLocation *loction, NSError *error) {

                NSLog(@"系统自带经纬度定位:%f,%f",loction.coordinate.latitude,loction.coordinate.longitude);

        }];

        //创建编码对象 CLGeocoder *geocoder=[[CLGeocoder alloc]init];

        [geocoder geocodeAddressString:@"杭州市" completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {

        // CLPlacemark : 地标

        // location : 位置对象

        // addressDictionary : 地址字典

        // name : 地址详情

        // locality : 城市

        if (error == nil) {

                CLPlacemark *pl = [placemarks firstObject];

                NSLog(@"%@-%@-%@", pl.name,@(pl.location.coordinate.latitude).stringValue,@(pl.location.coordinate.longitude).stringValue);

        } else {

                NSLog(@"错误");

        }

        }];

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容