I found this article and I'm trying to add functionality to Map
.
I have created this extension and I want to show an overlay to the map. Currently it's not being shown and I think it is because I have not specified a MKPolylineRenderer
How can I specify a renderer in this extension?
extension Map {
func mapStyle(_ mapType: MKMapType, showScale: Bool = true, showTraffic: Bool = false) -> some View {
let map = MKMapView.appearance()
map.mapType = mapType
map.showsScale = showScale
map.showsTraffic = showTraffic
return self
}
func addAnnotations(_ annotations: [MKAnnotation]) -> some View {
MKMapView.appearance().addAnnotations(annotations)
return self
}
func addOverlay(_ overlay: MKOverlay) -> some View {
MKMapView.appearance().addOverlay(overlay)
return self
}
}
View
Map(coordinateRegion: .constant(MKCoordinateRegion(route.polyline.boundingMapRect)))
.addOverlay(route.polyline)
I know I can use UIViewRepresentable
and I was using that but the issue is that it does not respond well to touching and moving around. It gets stuck and scrolling is hard. With Map
it works perfectly.