CLGeocoder reverseGeocodeLocation能源泄漏问题

时间:2015-10-07 16:50:16

标签: ios swift clgeocoder

我正在使用CLGeocoder()。reverseGeocodeLocation,当它运行时,我得到了非常高的"能源消耗和一些开销。这是我的代码:

    if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {

        var currentLatCoord = Double()
        if manager.location?.coordinate.latitude != nil {
            currentLatCoord = (manager.location?.coordinate.latitude)!
        } else {
            currentLatCoord = 0.0
            print("oops!")
        }

        var currentLongCoord = Double()
        if manager.location?.coordinate.longitude != nil {
            currentLongCoord = (manager.location?.coordinate.longitude)!
        } else {
            currentLongCoord = 0.0
            print("oops!")
        }

        CLGeocoder().reverseGeocodeLocation(CLLocation(latitude: currentLatCoord, longitude: currentLongCoord)) { (placemarks, error) -> Void in

            if error != nil {
                print("oops!")
                print(error)
                return
            }

            let placeArray = placemarks as [CLPlacemark]!
            var placeMark: CLPlacemark

            placeMark = placeArray![0]

            if let thoroughfare = placeMark.addressDictionary?["Thoroughfare"] as? String {
                self.locationLabel.text = thoroughfare
            } else {
                self.locationLabel.text = "Error!"
                print("oops!")
            }
        }
    }

这是调试器: Debugger

如果有人能找到原因,我搜索了这背后的原因而无法找到它,请告诉我!

0 个答案:

没有答案