我最近从传统的Mapbox SDK(版本1.6)更新到最新的Mapbox iOS SDK 3.x.如何使用Swift将公式中的Mapbox缩放到给定的半径?
在新版本中,我无法弄清楚如何将Mapbox MGLMapView缩放到以公里为单位的给定半径以适应屏幕。
在旧(版本1.6)RMMapView.zoomWithLatitudeLongitudeBoundsSouthWest
方法做这项工作如下:
func centerAndZoom(center: CLLocationCoordinate2D, kilometers: Float) {
let meters = Double(kilometers * 1000)
let region = MKCoordinateRegionMakeWithDistance(center, meters/2, meters/2);
let northEastLat = center.latitude - (region.span.latitudeDelta/2);
let northEastLon = center.longitude + (region.span.longitudeDelta/2);
let northEast = CLLocationCoordinate2D(latitude: northEastLat, longitude: northEastLon)
let southEastLat = center.latitude + (region.span.latitudeDelta/2);
let southEastLon = center.longitude - (region.span.longitudeDelta/2);
let southEast = CLLocationCoordinate2D(latitude: southEastLat, longitude: southEastLon)
self.mapView.zoomWithLatitudeLongitudeBoundsSouthWest(southEast, northEast: northEast, animated: true)
}
如何实现使用Swift在最新Mapbox半径放大?
感谢一大堆!保存我的一天 – AamirR
这可能是真正有用的,如果你真的可以在那里放置一些真实的代码,就像描述的情况一样。 (我的意思是转换半径+中心 - > MGLCoordinateBounds) – Aleksandr
人们应该如何知道sw和ne?我有一个重复使用的屏幕显示2个不同的注释。但它总是不同的位置度。我是否需要计算2个给定注释的sw/ne坐标? –