我在使用 iOS 中的 Mapbox 在不同屏幕尺寸上显示固定的爱尔兰 map 时遇到了一些问题。 MGLMapView.setVisibleCoordinates 似乎是我需要的,但它的行为并不像我期望的那样。我希望传入左下角坐标和右上角坐标,并定义一个无论屏幕大小如何都显示的矩形。
mapView.setVisibleCoordinates([CLLocationCoordinate2D(纬度:50.347676,经度:-11.444362),CLLocationCoordinate2D(纬度:56.375322,经度:-4.128659)],计数:2,edgePadding:UIEdgeInsets.zero,动画:false)
我也试过
mapView.setVisibleCoordinateBounds(MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: 50.347676, longitude: -11.444362)), ne: CLLocationCoordinate2D(latitude: 56.375322, longitude: -4.128659)), edgePadding: UIEdgeInsets.zero, 动画: false )
结果与下图相同。如您所见,iphone 5s 的布局非常完美,但我希望上面的代码能够在 ipad 上显示相同的 View ,但它被缩小了太多。如何跨设备显示相同的 View ?
最佳答案
好的,我开始工作了。 MGLMapView 上有一个相机方法,它会返回一个尽可能放大的相机,同时仍显示您指定的矩形。只需确保这是在 didFinishLoading
委托(delegate)方法中完成的。
let northeast = CLLocationCoordinate2D(latitude: 55.499130, longitude: -5.945938)
let southwest = CLLocationCoordinate2D(latitude: 51.133369, longitude: -10.531064)
let ireland = MGLCoordinateBounds(sw: southwest, ne: northeast)
let camera = mapView.camera(mapView.camera, fitting: ireland, edgePadding: UIEdgeInsets.zero)
mapView.setCamera(camera, animated: false)
关于ios - Mapbox iOS setVisibleCoordinates 未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273118/