gpt4 book ai didi

ios - 我的位置未显示在 MapKit 的 map 上

转载 作者:行者123 更新时间:2023-11-29 06:01:36 26 4
gpt4 key购买 nike

当我使用 let viewRegion = MKCooperativeRegionMakeWithDistance((userLocation?.coordinate)!, 600, 600) 时,效果很好,但显然 Swift 现在已将其替换为

let viewRegion = MKCooperativeRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, permanentMeters: 600)

我的位置不再出现在 map 上, map 显示正确的区域。这是我的代码。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
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.map.setRegion(viewRegion, animated: true)


}

最佳答案

首先希望您不要忘记从 CLLocationManagerDelegateMKMapViewDelegate 扩展您的 View Controller 。
您可以通过调用
从类中的任何位置直接从 locationManager 变量 private let locationManager: CLLocationManager = CLLocationManager() 访问用户位置userLocation = self.locationManager.location

也不要忘记将 View Controller 委托(delegate)给位置管理器和 map View :

locationManager.delegate = self
mapView.delegate = self

关于ios - 我的位置未显示在 MapKit 的 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54617571/

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