-1
我想通過名稱獲取城市的經度和緯度。 如果我輸入城市名稱爲「倫敦」我的輸出應該是它的座標Swift通過名稱獲取城市座標
我可以通過使用此代碼座標得到名稱:
var longitude :CLLocationDegrees = 41.0247
var latitude :CLLocationDegrees = 40.522
var location = CLLocation(latitude: latitude, longitude: longitude)
println(location)
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
println(location)
if error != nil {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
let pm = placemarks[0] as! CLPlacemark
println(pm.locality)
}
else
{
println("Problem with the data received from geocoder")
}
})