【发布时间】:2015-04-15 07:45:06
【问题描述】:
我是 Swift 新手,我需要获取用户的当前位置。我的意思是我需要得到纬度和经度。我试过这个:
class ViewController: UIViewController, CLLocationManagerDelegate{
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error) -> Void in
if (error != nil) {
println("ERROR:" + error.localizedDescription)
return
}
if placemarks.count > 0 {
let pm = placemarks[0] as CLPlacemark
self.displayLocationInfo(pm)
} else {
println("Error with data")
}
})
}
func displayLocationInfo(placemark: CLPlacemark) {
// self.locationManager.stopUpdatingLocation()
println(placemark.locality)
println(placemark.postalCode)
println(placemark.administrativeArea)
println(placemark.country)
println(placemark.location)
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError) {
println("Error:" + error.localizedDescription)
}
}
在这里我可以得到坐标,但它看起来像:
+/- 100.00m(速度 -1.00 mps / 路线 -1.00)@ 2/14/15,10:48:14 AM 莫斯科标准时间
我怎样才能只检索纬度和经度?
【问题讨论】:
标签: ios swift cllocationmanager cllocation