How to get MKMapView Directions in SwiftUI
在我的应用程序中,我正在使用 MKMapView SwiftUI 实现。我的地图运行良好,但我想在从 ContentView 中点击按钮时获取路线。我已经在下面更详细地解释了……
这是我的内容视图:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
struct ContentView: View {
var body: some View { Button(action: { |
这是我的地图视图:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
struct AppleMapView: UIViewRepresentable { var coordinate: CLLocationCoordinate2D func makeUIView(context: Context) -> MKMapView { func updateUIView(_ uiView: MKMapView, context: Context) { func makeCoordinator() -> Coordinator { func getDirections() { class Coordinator: NSObject, MKMapViewDelegate { func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { } |
谢谢。
在您的
这样你的
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
struct ContentView: View {
@State var directions: [CLLocation] = [] var body: some View { Button(action: { struct MapView: UIViewRepresentable { class Coordinator: NSObject, MKMapViewDelegate { init(_ parent: MapView) { func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { func makeCoordinator() -> Coordinator { func makeUIView(context: Context) -> MKMapView { func updateUIView(_ mapView: MKMapView, context: Context) { mapView.delegate = context.coordinator |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268670.html