ios - Mapbox iOS setVisibleCoordinates 未按预期运行

标签 ios mapbox mapbox-gl

我在使用 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 ?

IPad

Iphone 5s

最佳答案

好的,我开始工作了。 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/

相关文章:

ios - Swift:可解码

objective-c - 如何在 iphone 屏幕顶部(状态栏下方)添加一个栏?

iphone - cocos2d 中的自由运行/横向滚动类型游戏

javascript - 如何为 MapBox GL JS 使用 OpenMapTiles 服务器?

mapbox gl setFilter 按indexOf、包含或子字符串过滤

javascript - MapBox GL JS 标记偏移

objective-c - 如何使用 CAMediaTimingFunction 映射自定义值?

ios - 无法在 Mapbox SDK iOS 的 RMMapView 中一层一层地显示两层

javascript - 如何预填充 mapbox directions api 的起点和终点?

javascript - mapboxgl : create a map without displaying it