緯度経度から住所を文字情報で取得する。
コード
func revGeocoding(coordinate: CLLocationCoordinate2D)
{
let location = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
var geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks:[AnyObject]!, error:NSError!) -> Void in
if (error == nil && placemarks.count > 0) {
let placemark = placemarks[0] as CLPlacemark
println("Country = \(placemark.country)")
println("Postal Code = \(placemark.postalCode)")
println("Administrative Area = \(placemark.administrativeArea)")
println("Sub Administrative Area = \(placemark.subAdministrativeArea)")
println("Locality = \(placemark.locality)")
println("Sub Locality = \(placemark.subLocality)")
println("Throughfare = \(placemark.thoroughfare)")
} else if (error == nil && placemarks.count == 0) {
println("No results were returned.")
} else if (error != nil) {
println("An error occured = \(error.localizedDescription)")
}
})
}
CLPlacemarkに入っている情報
- Administrative Area
- 都道府県
- Locality
- 区や市名
- Sub Locality
- さらに細かい地域名
などなど。
端末の設定言語で取得される。