欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2017年04月23日 09:22:02   投稿:jingxian  
下面小編就為大家?guī)硪黄猧OS 原生地圖地理編碼與反地理編碼(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

當我們要在App實現(xiàn)功能:輸入地名,編碼為經(jīng)緯度,實現(xiàn)導(dǎo)航功能。

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

在文件中導(dǎo)入

#import <CoreLocation/CoreLocation.h>

地理編碼:

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

地理反編碼:

/** 
 地理反編碼 
 */
- (void)reverseGeocoder{ 
  //創(chuàng)建地理編碼對象 
  CLGeocoder *geocoder=[[CLGeocoder alloc]init]; 
   
  //經(jīng)度 
  NSString *longitude = @"113.23"; 
  //緯度 
  NSString *latitude = @"23.16"; 
   
   
  //創(chuàng)建位置 
  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 原生地圖地理編碼與反地理編碼(詳解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論