我能够获取地图视图的可见矩形,以及地图视图的中心点和跨度差也可以从mkmap视图方法中获取:
要获取可见区域:
现在我有了所有信息,如何使用计算方式计算出可见区域的半径呢?有人可以详细解释一下吗?
我看过这个问题,但是答案给出的是跨度而不是可见区域的半径。
mapView.visibleMapRect
被使用。要获取中心点: map view.centerCoordinate
被使用,并且要获取跨度: mapView.region.span
被使用。现在我有了所有信息,如何使用计算方式计算出可见区域的半径呢?有人可以详细解释一下吗?
我看过这个问题,但是答案给出的是跨度而不是可见区域的半径。
extension MKMapView{ var topLeftCoordinate: CLLocationCoordinate2D{ return convert(CGPoint.zero, toCoordinateFrom: self) } var radius: CLLocationDistance{ let centerLocation = CLLocation(latitude: centerCoordinate.latitude, longitude: centerCoordinate.longitude) let topLeftLocation = CLLocation(latitude: topLeftCoordinate.latitude, longitude: topLeftCoordinate.longitude) return centerLocation.distance(from: topLeftLocation) } }
- Finn Fahrenkrug