从 setUserTrackingMode(.Follow, animated: true) 设置 mapView 缩放距离

Set a mapView zoom distance from setUserTrackingMode(.Follow, animated: true)

我的地图视图当前跟随用户位置,但是,我想设置它放大的数量以显示距用户位置 2 公里的半径。

我的问题是你会怎么做,有缩放功能吗?还是我需要算出与该位置的距离并设置相应的 coordinates/region.

我对 swift 还是个新手,帮助真大!提前致谢

Apple Swift Documentation from MKMapView

When you initialize a map view, you should specify the initial region for that map to display. You do this by setting the region property of the map. A region is defined by a center point and a horizontal and vertical distance, referred to as the span. The span defines how much of the map at the given point should be visible and is also how you set the zoom level. Specifying a large span results in the user seeing a wide geographical area and corresponds to a low zoom level. Specifying a small span results in the user seeing a more narrow geographical area and corresponds to a higher zoom level.

因此您必须设置 regionspan 值。

var span = MKCoordinateSpanMake(0.02, 0.02)
var region = MKCoordinateRegion(center:CLLocationCoordinate2D(latitude: 
lat, longitude: long),span: span)
mapView.setRegion(region, animated: true)

我建议您应该关注 didUpdateLocationFunction 的更新,并将新的位置值设置为 lat 和 long 变量。跟踪模式不能保证恒定的缩放级别。