简体   繁体   English

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

[英]How can I include all the coordinates in the MapBox by adjusting the zoom level?

The code I have used is: 我使用的代码是:

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

I have 3 annotation and I want to see the 3 annotaion in the mapBox by adjusting the zoom level. 我有3个注释,我想通过调整缩放级别在mapBox中看到3个注释。 Please help me to find it out. 请帮我找出来。

There is method on MGLMapView that you can use: 您可以使用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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM