Набор карт местоположения с синей точкой - PullRequest
0 голосов
/ 29 мая 2020

Я пытаюсь создать приложение карт с помощью Mapkit. но я не могу получить доступ к синей точке, когда запускаю приложение на симуляторе. Я все еще новичок в Mapkit, и любые советы будут очень признательны. вот мой код. ps: я кодирую с использованием Swift 4.2 и Xcode 11

import UIKit
import MapKit
import CoreLocation

class mapViewController: UIViewController {

    let locationManager = CLLocationManager()

    @IBOutlet weak var mapView: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        locationManager.requestWhenInUseAuthorization()
        checkLocationServices()

    }

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

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

    func checkLocationServices() {
        if CLLocationManager.locationServicesEnabled() {
            setupLocationManager()
            checkLocationAuthorization()
        } else {

        }

    }

    func checkLocationAuthorization() {
        let pin = MKPointAnnotation()

        switch CLLocationManager.authorizationStatus() {
        case .authorizedWhenInUse:
            mapView.showsUserLocation = true
            mapView.addAnnotation(pin)
            break
        case .denied:
            break
        case .notDetermined:
            locationManager.requestWhenInUseAuthorization()
            break
        case .restricted:
            break
        case .authorizedAlways:
            break
        }
    }

}

extension mapViewController: CLLocationManagerDelegate {

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        // we'll be back
    }

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        //we'll be back
    }

}

enter image description here

1 Ответ

0 голосов
/ 29 мая 2020

Проверить меню симулятора: Функции> Местоположение> Пользовательское местоположение

enter image description here

...