xcode 8+当前位置迅速

时间:2016-12-23 18:32:37

标签: location swift3 mapkit

这是我的按钮点击代码

@IBAction func loc_btn_actn(_ sender: Any) {

    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestWhenInUseAuthorization()
    locationManager.startUpdatingLocation()

    shyMap.showsUserLocation = true

}

这是我的locationManager功能

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userLocation:CLLocation = locations[0] as CLLocation

    manager.stopUpdatingLocation()

    let coordinations = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude,longitude: userLocation.coordinate.longitude)
    let span = MKCoordinateSpanMake(0.2,0.2)
    let region = MKCoordinateRegion(center: coordinations, span: span)

    shyMap.setRegion(region, animated: true)

}

当我点击按钮时,我发现app delegate错误无法跟踪位置

0 个答案:

没有答案