如何通过调整缩放级别将所有坐标包含在MapBox中?

时间:2019-03-05 06:25:17

标签: annotations coordinates zoom mapbox

我使用的代码是:

let bounds = MGLCoordinateBounds(
    sw: CLLocationCoordinate2D(latitude: 40.7115, longitude: 10.3725),
    ne: CLLocationCoordinate2D(latitude: 40.7318, longitude: 10.4222))
    mapView.setVisibleCoordinateBounds(bounds, animated: false)

我有3个注释,我想通过调整缩放级别在mapBox中看到3个注释。请帮我找出来。

1 个答案:

答案 0 :(得分:2)

MGLMapView上有一种方法可以使用:

func showAllAnnotations() {
    guard let annotations = mapView.annotations else { return }

    // Either this...
    mapView.showAnnotations(annotations, edgePadding: UIEdgeInsets(top: 40, left: 35, bottom: 35, right: 35), animated: true)
    // or this.
    mapView.showAnnotations(annotations, animated: true)
}