swift 2.0中的func locationManager(管理器:CLLocationManager,didUpdateLocations位置:[CLLocation])

时间:2015-12-08 11:54:25

标签: swift cllocationmanager swift2.1

我的代码存在问题,didUpdateLocations函数从未被调用过。

我还添加了两个键NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription。我不知道如果有人可以提供帮助,会发生什么事

@IBOutlet weak var mapView: GMSMapView!

let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()

    locationManager.delegate = self
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.requestAlwaysAuthorization()


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}


func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
    if status == .AuthorizedWhenInUse
    {
        locationManager.startUpdatingLocation()
        mapView.myLocationEnabled = true
        mapView.settings.myLocationButton = true
    }
}
func locationManager (manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    if let location = locations.first
    {
        mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
        locationManager.stopUpdatingLocation()
        print(locationManager.location?.coordinate)

    }
}

0 个答案:

没有答案