【发布时间】:2016-01-10 19:19:20
【问题描述】:
我有一个应用程序可以获取您的位置并将其打印在标签上。但是当没有互联网连接时,我遇到了一个问题,纬度和经度没有显示。这是我的代码。有什么解决方案可以让纬度和经度脱机吗?。对不起我的语言。
@IBOutlet weak var latitude: UILabel!
@IBOutlet weak var Longitude: UILabel!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func mapsPressed(sender: UIButton) {
self.locationsManager()
}
func locationsManager(){
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error) -> Void in
if (error != nil) {
print("ERROR:" + error!.localizedDescription)
return
}
if let pm = placemarks?.first {
self.saveLatitudeLongitude(pm)
self.locationManager.stopUpdatingLocation()
}
else {
print("Error with data")
}
})
}
func saveLatitudeLongitude(placemark: CLPlacemark) {
// self.locationManager.stopUpdatingLocation()
self.latitude.text = String(placemark.location!.coordinate.latitude)
self.Longitude.text = String(placemark.location!.coordinate.longitude)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error:" + error.localizedDescription)
}
【问题讨论】:
标签: ios swift maps core-location