簡體   English   中英

位置標記未顯示Swift 4

[英]Location Marker Not Displaying Swift 4

我正在嘗試顯示用戶的當前位置,並將區域設置為他們的當前位置。

這是我的代碼。

    @IBOutlet weak var mapView: MKMapView!

    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.locationManager.requestWhenInUseAuthorization()

        if CLLocationManager.locationServicesEnabled() {

            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()

        }
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
        let userLocation = locations.last
        let viewRegion = MKCoordinateRegionMakeWithDistance((userLocation?.coordinate)!, 600, 600)
        self.mapView.setRegion(viewRegion, animated: true)
    }

怎么了:

  1. 地圖加載
  2. 地圖區域設置為當前位置
  3. 地圖區域將不斷更新到當前位置
  4. 當前位置被打印到控制台

什么不起作用:

  1. 沒有出現“藍色”當前位置指示符。

如果您知道我需要做些什么才能使“ Blue”當前位置指示器出現,將不勝感激。

你需要設置

mapView.showsUserLocation = true

viewDidLoad

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM