4
我正在尝试创建一个LocationManager
类来处理所有GPS数据。我需要多个视图控制器中的GPS数据。问题是函数被调用,但我没有得到坐标。我在状态栏中看到GPS图标,但几秒后它就会消失。Swift:不同类中的LocationManager
GPSTrackerManager.swift
class GPSTrackingManager: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
var seenError : Bool = false
func startTracking() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
locationManager.stopUpdatingLocation()
if ((error) != nil) {
if (seenError == false) {
seenError = true
print(error)
}
}
}
func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) {
//println("locations = \(locationManager)")
var latValue = locationManager.location.coordinate.latitude
var lonValue = locationManager.location.coordinate.longitude
println(latValue)
println(lonValue)
}
}
我如何在我的VC调用它ViewDidLoad
:
var tracking = GPSTrackingManager()
tracking.startTracking()
哇,这是愚蠢的,我没有看到。现在正在工作,谢谢! – EricDXS 2014-09-29 15:27:36