我有一个纬度/经度位置,我想将其转换为 Swift 中的位置名称字符串。做这个的最好方式是什么?我相信最好使用reverseGeocodeLocation函数,但不完全确定如何使用。这是我到目前为止所拥有的:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if (locationFixAchieved == false) {
locationFixAchieved = true
var locationArray = locations as NSArray
var locationObj = locationArray.lastObject as CLLocation
var coord = locationObj.coordinate
var latitude = coord.latitude
var longitude = coord.longitude
getCurrentWeatherData("\(longitude)", latitude: "\(latitude)")
reverseGeocodeLocation(location:coord, completionHandler: { (<#[AnyObject]!#>, <#NSError!#>) -> Void in
<#code#>
})
}
}
func reverseGeocodeLocation(location: CLLocation!, completionHandler: CLGeocodeCompletionHandler!){
}
你需要写这样的代码:
geocoder.reverseGeocodeLocation(currentLocation, completionHandler: {
placemarks, error in
if error == nil && placemarks.count > 0 {
self.placeMark = placemarks.last as? CLPlacemark
self.adressLabel.text = "\(self.placeMark!.thoroughfare)\n\(self.placeMark!.postalCode) \(self.placeMark!.locality)\n\(self.placeMark!.country)"
self.manager.stopUpdatingLocation()
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)