I recently updated from legacy Mapbox SDK (version 1.6) to latest Mapbox iOS SDK 3.x.
In new version I am not able to figure out how to zoom Mapbox MGLMapView to a given radius in kilometers to fit on screen.
In old (version 1.6) RMMapView.zoomWithLatitudeLongitudeBoundsSouthWest
method does the job as following:
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)
}
How to achieve a radius zoom in latest Mapbox using Swift?