higan96技術メモ

https://github.com/higan96

CoreLocationで国、都道府県、市区町村の取得

import CoreLocation
 
let location:CLLocation = CLLocation(latitude: lat, longitude:lon)
geocoder.reverseGeocodeLocation(location, completionHandler:{(placeMarks, error) -> Void in
  if error == nil {
    if placeMarks.count > 0{
      let placemark: CLPlacemark = placeMarks[0] as CLPlacemark
      println(placemark.ISOcountryCode)     // JP
      println(placemark.administrativeArea)  // 都道府県
      println(placemark.subAdministrativeArea) // 群
      println(placemark.locality) // 市町村区
    }
  }else{
    println(error)
  }
})