您必须重写
CLLocationManager.didUpdateLocations(CLLocationManagerDelegate的一部分)才能在位置管理器检索当前位置时得到通知:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if let location = locations.last{ let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)) self.map.setRegion(region, animated: true) }}注意:如果目标是iOS
8或更高版本,则必须在Info.plist中包括
NSLocationAlwaysUsageDescription或
NSLocationWhenInUseUsageDescription键,才能使定位服务正常工作。



