小编Has*_*ute的帖子

如何在swift的地图视图上显示位置?我相信我的代码是最新的,但模拟器没有显示位置或蓝点?

我正在尝试使用 swift 上的地图视图在我的当前位置和地图上显示一个蓝点。但是它没有显示我的位置,也没有显示蓝点我对我的代码非常肯定,但我无法显示它!应该是设置的问题吧?

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController {

    @IBOutlet weak var mapView: MKMapView!

    let locationManager = CLLocationManager()
    let regionInMeters: Double = 1000

    override func viewDidLoad() {
        super.viewDidLoad()
        checkLocationServices()
    }


    func setupLocationManager() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
    }


    func centerViewOnUserLocation() {
        if let location = locationManager.location?.coordinate {
            let region = MKCoordinateRegion.init(center: location, latitudinalMeters: regionInMeters, longitudinalMeters: regionInMeters)
            mapView.setRegion(region, animated: true)
        }
    }
    func checkLocationServices() {
        if CLLocationManager.locationServicesEnabled() {
            setupLocationManager()
            checkLocationAuthorrization()
        } else {
            // Show …
Run Code Online (Sandbox Code Playgroud)

core-location mapkit ios swift

4
推荐指数
2
解决办法
3966
查看次数

标签 统计

core-location ×1

ios ×1

mapkit ×1

swift ×1