ios - 使用户位置在地图上可见不起作用
问题描述
如果我正在运行我的代码,圆形的蓝点不会显示在地图上。地图上可见的用户位置不起作用。我找不到那个问题。谁能找到问题?
import UIKit
import MapKit
import CoreLocation
class GPSNewBin: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var zurueckButton: UIButton!
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Ask for Authorisation from the User.
self.locationManager.requestAlwaysAuthorization()
// For use in foreground
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
let locValue: CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
let userLocation = locations.last
let viewRegion = MKCoordinateRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, longitudinalMeters: 600)
self.mapView.setRegion(viewRegion, animated: true)
}
}
非常感谢 :)
解决方案
推荐阅读
- c# - 在WEB API C#、SOAP架构中,如何通过token和roles来实现授权,通过使用带有存储过程的repositories?
- assembly - 在 arm-none-eabi-gdb 模拟器中,来自程序入口点的 ldr 似乎给出了无意义的结果
- scheme - 在球拍中定义 mylength 函数
- java - 如何检查请求正文中的输入类型布尔值
- c# - 检查文本框输入自动增加数量由输入总记录确定
- ruby - 尝试一起使用 jekyll-paginate-v2 和 jekyll-multiple-language-plugin
- markdown - 双美元符号`$$`不能显示在gitbook的markdown代码块中
- php - 从 php 调用 python 脚本时打开(文件名)不起作用
- excel - Excel - 自动填充(复制)复制公式但显示原始值
- forms - Symfony / Form Type - 不以 single_text 小部件样式填充日期时间的编辑表单数据