swift - 在 swift 上显示用户位置

标签 swift mapkit core-location

我正在编写在 map 上显示我的位置的代码。

我知道该位置实际上无法在模拟器上使用,但它可以显示带有蓝色圆圈的虚假位置。

在我的 map 中,它只显示一张没有蓝色圆圈的大 map 。 为什么我会收到此错误?

(Could not retrieve region info)

它可以构建,但我在输出时收到错误,它显示:

"2019-12-11 22:07:53.809967+0100 Ecologia[8465:265293] Metal API Validation Enabled 2019-12-11 22:07:54.001955+0100 Ecologia[8465:265293] libMobileGestalt MobileGestalt.c:1647: Could not retrieve region info"

这是我的代码:

//
//  ViewController.swift
//  Ecologia
//
//  Created by Antonio Trotta on 11/12/2019.
//  Copyright © 2019 Antonio Trotta. All rights reserved.
//

import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController {

    @IBOutlet weak var Map: MKMapView!
    let locationManager:CLLocationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = kCLDistanceFilterNone
        locationManager.startUpdatingLocation()
        Map.showsUserLocation = true
    }
}

最佳答案

检查模拟器菜单:调试 > 位置 >

enter image description here

关于swift - 在 swift 上显示用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59294260/

相关文章:

swift - 使用任何 RGB 颜色空间时无法获得有效的 CGContext?

swift - addDocument 完成处理程序永远不会被调用

ios - 将 Mapkit 设置为仅包含城市名称的位置

ios - kCLAuthorizationStatusRestricted 显示在我的一个应用程序中,但同一设备上的另一个应用程序中没有显示

swift - 以编程方式填充 STPPaymentCardTextField

ios - 添加 NavigationLink 时的 Swiftui 问题

ios - CoreLocation 区域委托(delegate)未调用

ios - 在 iOS 中,使用 Swift,我想显示用户的位置,但是蓝点没有出现在 MapView 上

ios - 如何放大和居中用户位置(Objective-C)

objective-c - Objective-C : How to implement MapKit Method - (NSSet *)annotationsInMapRect:(MKMapRect)mapRect