我是SwiftUI的新手,在学习完教程后,我尝试设置地图的初始缩放级别,因为它的缩放范围非常远。
我一直在读通过这个,但它不是发出很大的意义上,我似乎无法找到一行代码,指定int
或double
指定变焦(例如,在谷歌地图API是这样的情况)
我尝试更改MKCoordinateRegion
withMKCoordinateRegionMakeWithDistance
并将第三个arg设置为a,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)
}
}
此增量值将更改缩放级别。
// set span (radius of points)
let span = MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)
如果将0.5更改为0.01,则地图将放大。取0.8之类的较高值,地图将缩小。
希望我提供了足够的信息。祝好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句