gpt4 book ai didi

ios - 关闭项目后位置不再记录

转载 作者:行者123 更新时间:2023-11-28 07:37:46 26 4
gpt4 key购买 nike

我创建了一个 View 并添加了 Mapkit,然后编写代码来获取用户位置并将其显示在 map 上。第一次它似乎工作,在关闭 Xcode 并打开项目(通过终端“打开项目名称”)后它似乎停止显示位置,我不确定这是否是一个错误。我尝试了不同的模拟器,对于 iPhone 8 plus,我得到以下错误

2018-10-24 21:04:44.112488-0400 Jama3aV2[55977:5431299] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x7fbe67d00a00] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.112802-0400 Jama3aV2[55977:5431299] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C2.1:2][0x7fbe67d00a00] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.116124-0400 Jama3aV2[55977:5431299] TIC 读取状态 [2:0x0]: 1:57
2018-10-24 21:04:44.116306-0400 Jama3aV2[55977:5431299] TIC 读取状态 [2:0x0]: 1:57
2018-10-24 21:04:44.404369-0400 Jama3aV2[55977:5431298] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x7fbe67f0e490] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.404509-0400 Jama3aV2[55977:5431298] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C6.1:2][0x7fbe67f0e490] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.404894-0400 Jama3aV2[55977:5431298] TIC 读取状态 [6:0x0]: 1:57
2018-10-24 21:04:44.405132-0400 Jama3aV2[55977:5431298] TIC 读取状态 [6:0x0]: 1:57
2018-10-24 21:04:44.626215-0400 Jama3aV2[55977:5431297] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C8.1:2][0x7fbe67d07270] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.626364-0400 Jama3aV2[55977:5431297] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C8.1:2][0x7fbe67d07270] 获取输出帧失败,状态 8196
2018-10-24 21:04:44.626818-0400 Jama3aV2[55977:5431297] TIC 读取状态 [8:0x0]: 1:57
2018-10-24 21:04:44.626962-0400 Jama3aV2[55977:5431297] TIC 读取状态 [8:0x0]: 1:57

我不确定我做错了什么,我在我的 info.plist 中添加了“privacy:location When In Use Description”。这是我的代码:

``导入 UIKit导入 MapKit导入核心位置

类 MapViewController: UIViewController, MKMapViewDelegate {

@IBOutlet weak var addressTextView: UITextField!
@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 checkLocationServices() {
if CLLocationManager.locationServicesEnabled() {
setupLocationManager()
checkLocationAuthorization()
} else {


}
}

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

func checkLocationAuthorization() {
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse:
mapView.showsUserLocation = true
centerViewLocationServices()
locationManager.startUpdatingLocation()
break
case .denied:
break
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
break
case .restricted:
break
case .authorizedAlways:
break

}
}

扩展 MapViewController:CLLocationManagerDelegate {

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion.init(center: center, latitudinalMeters: regionInMeters, longitudinalMeters: regionInMeters)
mapView.setRegion(region, animated: true)
}


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
checkLocationAuthorization()
}

}``

我遵循了以下 youtube 教程:

https://www.youtube.com/watch?v=WPpaAy73nJc&lc=z22phjvoivbcuxs4104t1aokgvm4f0nlq11ws3nrrojgbk0h00410.1540259497069676

最佳答案

如果您希望始终在控制台中看到它,只需使用 print 打印出用户位置的经纬度

在 locationManager 中执行此操作:

打印(位置.坐标.纬度)打印(位置.坐标.经度)

哦,是的,永远不要在模拟器上使用定位,它们很烂,请使用合适的手机

关于ios - 关闭项目后位置不再记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52979943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com