Map(position: $position, selection: $selectedResult) { MapPolyline(coordinates: track).stroke(.blue, lineWidth: 5) } When the @State track: [CLLocationCoordinates] is growing with new data (new coordinates appended) how can we reach that Map and MapPolyline is automatically refreshed?
Autorefresh MapPolyline when route data grows
Same Q. Need SwiftUI implementation of MKPolylineRenderer to be added to iOS 17 sdk.
In ContentView, use an array of MKPolylines, manage them in some function that adds/removes polylines based on user interaction, and then place them in the Map() in a ForEach loop. It may not be as efficient as they claim MKMultiPolyline to be, but it gets n-number of polylines on the map.
Top of the ContentView struct:
@State private var multiPolylines = [MKPolyline]()
Using them in the Map:
Map() {
ForEach(multiPolylines, id:\.self) { polyline in
MapPolyline(polyline)
.stroke(.pink, lineWidth: 3)
}
}
Did you manage to run the code on a device? Seems like MapPolyline has a mismatch with some imports. Just doesn't seem to work on a real device, simulator all fine..dyld[727]: Symbol not found: _$s15_MapKit_SwiftUI0A8PolylineV11coordinatesACSaySo22CLLocationCoordinate2DVG_tcfC Referenced from: <E9A5FA65-D271-398C-B746-E6F3B8951F53> /private/var/containers/Bundle/Application/89A67FF0-1A6B-4362-B5EA-3BF51DE57BF0/MyApp.app/MyApp Expected in: <CE0BFEFF-34DF-3B0D-A41D-DABB2142FB99> /System/Library/Frameworks/_MapKit_SwiftUI.framework/_MapKit_SwiftUI