iOS OC 根據經緯度獲取城市等信息

// 創建經緯度
CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
//創建一個譯碼器
CLGeocoder *cLGeocoder = [[CLGeocoder alloc] init];
[cLGeocoder reverseGeocodeLocation:userLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *place = [placemarks objectAtIndex:0];
// 位置名
  NSLog(@"name,%@",place.name);
  // 街道
  NSLog(@"thoroughfare,%@",place.thoroughfare);
  // 子街道
  NSLog(@"subThoroughfare,%@",place.subThoroughfare);
  // 市
  NSLog(@"locality,%@",place.locality);
  // 區
  NSLog(@"subLocality,%@",place.subLocality);
  // 國家
  NSLog(@"country,%@",place.country);
}
}];

/* CLPlacemark中屬性含義
name 地名

thoroughfare 街道

subThoroughfare 街道相關信息,例如門牌等
locality 城市

subLocality 城市相關信息,例如標志性建筑

administrativeArea 直轄市

subAdministrativeArea 其他行政區域信息(自治區等)

postalCode 郵編

ISOcountryCode 國家編碼

country 國家

inlandWater 水源,湖泊

ocean 海洋

areasOfInterest 關聯的或利益相關的地標
*/

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容