mapkit - 通过点击 pin 注释转到 SwiftUI 视图
问题描述
我想通过点击 pin 注释进入新的 SwiftUI 视图 我已经在其上创建了 mapView 和 pin 注释 我想通过点击这个 pin 进入 SwiftUI 视图 如何在 Uiviewrepresentable 视图中进入 SwiftUi 视图
这是我的地图视图
func updateUIView(_ view: MKMapView, context: Context) {
let locationManager = CLLocationManager()
let path = Datas.path
var locationsDic: [[String: Any]] = [["latitude": 0, "longitude": 0],["latitude": 0, "longitude": 0],["latitude": 0, "longitude": 0]]
view.showsUserLocation = true
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
let locValue:CLLocationCoordinate2D = locationManager.location!.coordinate
let coordinate = CLLocationCoordinate2D(
latitude: locValue.latitude, longitude: locValue.longitude)
locationsDic[0]["latitude"] = locValue.latitude.advanced(by: 0.0)
locationsDic[0]["longitude"] = locValue.longitude.advanced(by: 0.0)
(locationsDic as NSArray).write(toFile: path, atomically: true)
let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)
let region = MKCoordinateRegion(center: coordinate, span: span)
view.setRegion(region, animated: true)
let originAnnotation = MKPointAnnotation()
originAnnotation.title = "origin"
originAnnotation.coordinate = CLLocationCoordinate2D(latitude: 37.332072300, longitude: -122.011138100)
view.addAnnotation(originAnnotation)
})
}
locationsDic = NSArray(contentsOfFile: path) as! [[String: Any]]}}
解决方案
推荐阅读
- r - 尽管在 R 中存在具有相似值的其他字符串,我可以只替换一个字符串吗
- javascript - React 组件看起来在其实例中具有静态共享状态
- python - 在 Apache 的 mod_wsgi 中运行 Python 看不到 /usr/local/lib64/python3.6/site-packages 中的 Python 模块
- dart - 之间有什么不同
和 和 和 - python - 将数据框添加到绘图子图中
- flutter - Flutter:'onError' 在 runZoned 函数上已弃用
- sql - 在选择查询中隐藏列?
- javascript - how to merge 4 arrays object using lodash
- android - Flutter:允许安装在同一部手机上的两个 Flutter 应用程序之间进行通信
- github - 如何通过命令行界面邀请人们到私人 GitHub 存储库?