I need help in displaying an overlay with where in the world is night and day on MKMapView.
The idea is to display where is night a black opaque color, and where is day nothing. I've been trying to use MKOverlay, but had no luck.
Minimal reproducing code provided.
struct OurMapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
mapView.showsUserLocation = true
mapView.mapType = .standard // Set the map type to satellite
return mapView
}
func updateUIView(_ uiView: MKMapView, context: Context) {
}
}
EDIT: I am aiming to do something similar, but without toggles, just display where is day and night: https://appadvice.com/app/day-night-map/741375889
Since I mainly deal with SwiftUI, and MapKit is only fully possible in SwiftUI since iOS 17, I'll show you my idea (but requires SwiftUI and target must be iOS 17).
I created an array from CLLocationCoordinate2D to display a polygon on the map.