国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 原生地圖地理編碼與反地理編碼(詳解)

2019-10-21 18:46:52
字體:
來源:轉載
供稿:網友

當我們要在App實現功能:輸入地名,編碼為經緯度,實現導航功能。

那么,我需要用到原生地圖中的地理編碼功能,而在Core Location中主要包含了定位、地理編碼(包括反編碼)功能。

在文件中導入

#import <CoreLocation/CoreLocation.h>

地理編碼:

/**  地理編碼  */- (void)geocoder {      CLGeocoder *geocoder=[[CLGeocoder alloc]init];      NSString *addressStr = @"廣東省深圳市寶安區";//位置信息      [geocoder geocodeAddressString:addressStr completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {     if (error!=nil || placemarks.count==0) {       return ;     }     //創建placemark對象     CLPlacemark *placemark=[placemarks firstObject];     //經度     NSString *longitude =[NSString stringWithFormat:@"%f",placemark.location.coordinate.longitude];     //緯度     NSString *latitude =[NSString stringWithFormat:@"%f",placemark.location.coordinate.latitude];          NSLog(@"經度:%@,緯度:%@",longitude,latitude);        }];    }

地理反編碼:

/**  地理反編碼  */- (void)reverseGeocoder{   //創建地理編碼對象   CLGeocoder *geocoder=[[CLGeocoder alloc]init];      //經度   NSString *longitude = @"113.23";   //緯度   NSString *latitude = @"23.16";         //創建位置   CLLocation *location=[[CLLocation alloc]initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];         //反地理編碼   [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {     //判斷是否有錯誤或者placemarks是否為空     if (error !=nil || placemarks.count==0) {       NSLog(@"%@",error);       return ;     }     for (CLPlacemark *placemark in placemarks) {       //詳細地址       NSString *addressStr = placemark.name;       NSLog(@"詳細地址1:%@",addressStr);       NSLog(@"詳細地址2:%@",placemark.addressDictionary);       NSLog(@"詳細地址3:%@",placemark.locality);     }        }]; }

以上這篇iOS 原生地圖地理編碼與反地理編碼(詳解)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安龙县| 滁州市| 钟山县| 绩溪县| 伊通| 新营市| 德昌县| 鄂温| 浦东新区| 繁峙县| 页游| 峨眉山市| 高州市| 南昌市| 杂多县| 宜春市| 灌云县| 察雅县| 郧西县| 正蓝旗| 个旧市| 佛教| 名山县| 图木舒克市| 四子王旗| 昌乐县| 上林县| 博白县| 宿松县| 象州县| 侯马市| 黄大仙区| 横山县| 纳雍县| 双柏县| 鄂州市| 昌平区| 上高县| 宁海县| 新田县| 三明市|