mapKit Apple:地名错误且用户没有焦点地图

mapKit Apple: Bug with places' names and no focus map on user

我尝试通过 segue 通过 button1 从带有地图的 VC1 转到 VC2,它必须将焦点固定在我在地图中心的位置并且它有错误。它不关注用户,但如果我按下按钮 2,返回并按下按钮 1,它就会关注用户。而且我不明白我需要在哪里修复它。

还有最后一个错误:如果我设置了巨大的 regionInMeters 值,例如10000 米,我缩放,当我尝试对用户使用此方法时,它在两种情况下都显示地名、街道和错误(图像)。如果我设置低 - 500,在这些情况下它会显示正确的关闭,但只是在用户周围的位置,如果我在另一个城市切换到那里并放大,它仍然会出现这个错误。同样的故事,重点放在地方。在巨大的高度上 - 国家名称、城市、河流到处都是正确的

let annotationIdentifire = "annotationIdentifire"
let locationManager = CLLocationManager()
let regionInMeters = 500.00
var incomeSegueIdentifire = ""
override func viewDidLoad() {
    super.viewDidLoad()

    addressLabel.text = ""
    mapView.delegate = self
    setupMapView()
    checkLocationServices()
} 
private func checkLocationServices(){

    if CLLocationManager.locationServicesEnabled() {
        setupLocationManager()
        checkLocationAuthorization()
} else{...}
private func checkLocationAuthorization() {
    switch CLLocationManager.authorizationStatus() {
    case .authorizedWhenInUse:
        mapView.showsUserLocation = true
        if incomeSegueIdentifire == "getAddress" { showUserLocation() }
        break
//other cases
}

另外,我在 VC1 上还有另一个带有 segue 的 button2,它打开带有地图的 VC2,它专注于我设置的位置和地址,在这种情况下,我在地图上有 button3,它专注于我正确:

  @IBAction func centerViewInUserLocation() {
    showUserLocation()
}

有一种方法是我用来关注用户的。

private func showUserLocation() {
    if let location = locationManager.location?.coordinate {
        let region = MKCoordinateRegion(center: location,
                                        latitudinalMeters: regionInMeters,
                                        longitudinalMeters: regionInMeters)
        mapView.setRegion(region, animated: true)
    }
}

我在另一个设置的incomeSegueIdentifire值class

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         guard let identifire = segue.identifier, let mapVC = segue.destination as? MapViewController else { return }
    mapVC.incomeSegueIdentifire = identifire
}

我找不到如何修复地名错误,但我修复了主要错误(当通过 segue 打开地图时,它必须关注用户,但事实并非如此)。

我得到 mistake:Could 未检索区域信息。并试图为这个案例寻找答案,但没有找到。找到了几个关于这个错误的答案的案例,上面说,代码没问题,但仍然是错误的,主要的 answer/advice - 尝试在你的真实设备上 运行 它,也许它是正确的,我不知道'有 iphone/ipad。但是对于模拟器我通过延迟异步调用这个方法来修复它,它对我有用)

private func checkLocationAuthorization() {
    switch CLLocationManager.authorizationStatus() {
    case .authorizedWhenInUse:
        mapView.showsUserLocation = true
        if incomeSegueIdentifire == "getAddress" { DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            self.showUserLocation()
            }
        }
        //other cases
    }
}

但是,如果您对这些问题有任何想法,我会很高兴知道))