定位:需要在info.plist中添加
NSLocationAlwaysUsageDescription 需要始終訪問您的位置
NSLocationUsageDescription 需要訪問您的位置
NSLocationWhenInUseUsageDescription 需要您的同意,在使用期間訪問位置
NSLocationAlwaysAndWhenInUseUsageDescription 需要訪問您的位置
項目添加框架CoreLocation.framework,并引入
#import <CoreLocation/CoreLocation.h>
-(void)startLocation {
?????????[[MapLocationManager shareInstance]startSystemLocationWithRes:^(CLLocation *loction, NSError *error) {
????????????????NSLog(@"系統(tǒng)自帶經(jīng)緯度定位:%f,%f",loction.coordinate.latitude,loction.coordinate.longitude);
????????}];
? ? ? ? //創(chuàng)建編碼對象 CLGeocoder *geocoder=[[CLGeocoder alloc]init];
? ? ? ? [geocoder geocodeAddressString:@"杭州市" completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {
? ? ? ? // CLPlacemark : 地標(biāo)
????????// 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(@"錯誤");
????????}
????????}];
}