如果我正在运行代码,则圆角的蓝点不会显示在 map 上。在 map 上可见的用户位置无效。我找不到这个问题。谁能找到问题?

import UIKit
import MapKit
import CoreLocation

class GPSNewBin: UIViewController, CLLocationManagerDelegate {


    @IBOutlet weak var mapView: MKMapView!
    @IBOutlet weak var zurueckButton: UIButton!

    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Ask for Authorisation from the User.
        self.locationManager.requestAlwaysAuthorization()

        // For use in foreground
        self.locationManager.requestWhenInUseAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()
        }
    }


    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        //guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
        let locValue: CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
        let userLocation = locations.last
        let viewRegion = MKCoordinateRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, longitudinalMeters: 600)
        self.mapView.setRegion(viewRegion, animated: true)
    }

}

非常感谢 :)

最佳答案

您可以从情节提要中启用用户位置:

ios - 在 map 上显示用户位置无效-LMLPHP

要么

您也可以使用以下代码启用它:

mapView.showsUserLocation = true

07-27 13:31