I thought about this warning for a long time, and after a while I found out what my problem was. When creating a map with the MapKit
framework, the program returned this error depending on the values that were passed as latitudeDelta
and longitudeDelta
in MKCoordinateSpan
. So, I just reduced these values, which brought the map closer, but the warnings stopped appearing. My working code is error-free:
import SwiftUI
import MapKit
struct MapView: View {
var coordinate: CLLocationCoordinate2D
@State private var region = MKCoordinateRegion()
var body: some View {
Map(coordinateRegion: $region).onAppear() {
setRegion(coordinate)
}
}
private func setRegion(_ coordinate: CLLocationCoordinate2D) {
region = MKCoordinateRegion(center: coordinate, span: MKCoordinateSpan(latitudeDelta: 0.040, longitudeDelta: 0.040))
}
}
struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView1(coordinate: CLLocationCoordinate2D(latitude: 55.7522200, longitude: 37.6155600))
}
}
Before that, the values were as follows::
region = MKCoordinateRegion(center: coordinate, span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))