我正在使用CLLocationManager获取当前的纬度和经度,但委托方法didUpdateLocation未被调用 - Swift3.0

时间:2017-03-31 09:49:26

标签: ios swift geolocation xcode8 core-location

我试图使用CLLocationManager框架来访问用户的位置,但是当我打电话时 self.locationManager.startUpdatingLocation()

locationManager:didUpdateLocations:或locationManager:didFailWithError:都没有被调用。

这是代码

func currentLatLong() - >无效{

        self.currentLatitude = nil
        self.currentLongitude = nil
        startLocation = nil
        self.locationManager = CLLocationManager()
        self.locationManager.delegate = self;
        self.locationManager.distanceFilter = kCLDistanceFilterNone
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.requestAlwaysAuthorization()
        self.locationManager.startMonitoringSignificantLocationChanges()
        self.locationManager.startUpdatingLocation()


    }
    public func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
        self.currentLatitude = String(locValue.latitude)
        self.currentLongitude = String(locValue.longitude)
        self.locationManager.stopUpdatingLocation()
    }

    public func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
        print(error)
   }

我错过了什么吗?

我也将这些添加到我的.info文件

NSLocationAlwaysUsageDescription ---我需要位置

NSLocationWhenInUseUsageDescription ---我需要位置

0 个答案:

没有答案