I'm building an app entirely in SwiftUI as part of a University research project. I'd like to use the .mutedStandard
map type and to remove all but a few of Apple's points of interest (POI) as they can become quite cluttered. My approach works perfectly fine when the map is first loaded, but things change as soon as the mapRegion
binding changes in the parent view.
The region and annotations update exactly as desired when the binding of the mapRegion changes, but from the first change the map begins to ignore the .mapType
and .pointOfInterstFilter
created in the map's .onAppear
code, thus reverting back to Apple's default, POI-littered map.
I've played around with moving these to the view's init()
, attempting reloads using .id()
all to no avail. If anyone has some suggestions, I'd be very greatful!
Here's the view code:
struct LocationPickerMap: View {
@Binding var mapRegion: MKCoordinateRegion
var annotations: [Markers]
let mapFilters: MKPointOfInterestFilter = MKPointOfInterestFilter(including: [.airport, .beach, .gasStation, .hospital, .library, .park, .police, .postOffice, .school, .university, .zoo])
var body: some View {
VStack {
Map(
coordinateRegion: $mapRegion,
interactionModes: [],
showsUserLocation: true,
annotationItems: annotations
) { item in
MapMarker(
coordinate: CLLocationCoordinate2D(
latitude: item.coordinate.latitude,
longitude: item.coordinate.longitude
),
tint: Color.red
)
}
}
.onAppear {
MKMapView.appearance().mapType = .mutedStandard
MKMapView.appearance().pointOfInterestFilter = .some(mapFilters)
}
}
}
Ryan