首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >蓝点位置mapkit

蓝点位置mapkit
EN

Stack Overflow用户
提问于 2020-05-29 11:04:19
回答 1查看 51关注 0票数 0

我正在尝试使用Mapkit制作一个地图应用程序。但是当我在模拟器上运行应用程序时,我似乎无法访问蓝点。我仍然是Mapkit的新手,如果有任何建议,我将不胜感激。这是我的代码。附言:我使用Swift 4.2和Xcode 11进行编码

代码语言:javascript
运行
复制
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
    }

}

EN

回答 1

Stack Overflow用户

发布于 2020-05-29 11:18:39

检查模拟器菜单:功能>位置>自定义位置

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62078010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档