我是 SwiftUI 的新手,在学习完教程后,我尝试设置地图的初始缩放级别,因为它缩小了很远。
我一直在阅读这篇文章,但它没有多大意义我似乎无法找到一行代码来指定一个int或一个double指定缩放(例如在谷歌地图 API 中就是这种情况)
我尝试更改我的MKCoordinateRegionwithMKCoordinateRegionMakeWithDistance并将第三个 arg 设置为let zoom = CLLocationDistance(10)但这不起作用。
这是我的代码:
import SwiftUI
import MapKit
struct MapView: UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<MapView>) -> MKMapView {
MKMapView()
}
func updateUIView(_ uiView: MKMapView, context: UIViewRepresentableContext<MapView>) {
// set coordinates (lat lon)
let coords = CLLocationCoordinate2D(latitude: 53.062640, longitude: -2.968900)
// set span (radius of points)
let span = MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)
// set region
let region = MKCoordinateRegion(center: coords, span: span)
// set the view
uiView.setRegion(region, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
Tob*_*ink 10
此增量值会更改缩放级别。
// set span (radius of points)
let span = MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)
Run Code Online (Sandbox Code Playgroud)
如果将 0.5 更改为 0.01,则地图将放大。取值(例如 0.8),地图将缩小。
希望我提供了足够的信息。祝你好运!
| 归档时间: |
|
| 查看次数: |
2251 次 |
| 最近记录: |