我想了很久这个警告,过了一会儿我发现我的问题是什么。使用MapKit
框架创建地图时,程序根据传递的值返回latitudeDelta
此错误longitudeDelta
。MKCoordinateSpan
所以,我只是减少了这些值,使地图更接近,但警告不再出现。我的工作代码没有错误:
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))
}
}
在此之前,这些值如下:
region = MKCoordinateRegion(center: coordinate, span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))