我如何以自己的位置为中心地图



在Xcode应用程序上,我显示了数据库中的许多引脚,但我的位置不在我的位置上

覆盖func viewdidload(({ super.viewdidload((

    // Do any additional setup after loading the view.
    // Create coordinates from location lat/long
    var poiCoodinates = CLLocationCoordinate2D()
    tab = selectedEtablissement as! [EtablissementModel]
    for item in 0..<tab.count{
        poiCoodinates.latitude = tab[item].lonetablissement!
        poiCoodinates.longitude = tab[item].lngetablissement!
        // Zoom to region
        let viewRegion: MKCoordinateRegion = MKCoordinateRegion.init(center: poiCoodinates, latitudinalMeters: 750, longitudinalMeters: 750)
        self.mapB******.setRegion(viewRegion, animated: true)
        // Plot pin
        let pin: MKPointAnnotation = MKPointAnnotation()
        pin.coordinate = poiCoodinates
        self.mapB*******.addAnnotation(pin)
        //add title to the pin
        pin.title = tab[item].nometablissement
    }
    locationManager.requestWhenInUseAuthorization()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.distanceFilter = kCLDistanceFilterNone
    locationManager.startUpdatingLocation()
    mapBieres.showsUserLocation = true
    self.locationManager.stopUpdatingLocation()
}

这些引脚显示在许多城市上,并且使用此代码,我的位置将显示,但地图并未以我的位置为中心。我想要地图上的所有引脚,但地图以我的位置为中心。谢谢

`import MapKit
 import CoreLocation
 class ViewController: UIViewController {
 var locationManager = CLLocationManager()
 @IBOutlet weak var mapView: MKMapView!

  func setLocation() { // Seeting up current location
        locationManager.delegate = self as CLLocationManagerDelegate
        locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }
   // Setting the current location to the ashton building, & the zoom of the map
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let locationOfUser = locations[0]
        let lat = locationOfUser.coordinate.latitude
        let long = locationOfUser.coordinate.longitude
        let latDelta: CLLocationDegrees = 0.003 // Distance from the map
        let lonDelta: CLLocationDegrees = 0.003
        let span = MKCoordinateSpan(latitudeDelta: latDelta, longitudeDelta: lonDelta)
        let location = CLLocationCoordinate2D(latitude: lat, longitude: long)
        let region = MKCoordinateRegion(center: location, span: span)
        mapView.setRegion(region, animated: true)
    }
}`

以下代码应帮助您设置当前位置以及地图的距离变焦。(如果我没记错的话,请确保在设置中打开当前位置(。 希望无论如何都可以帮助您,必须浏览我的旧迅速作业:(