gpt4 book ai didi

ios - 如何使用 Swift 将 Mapbox 缩放到以千米为单位的给定半径?

转载 作者:可可西里 更新时间:2023-11-01 00:58:38 25 4
gpt4 key购买 nike

我最近从旧版 Mapbox SDK(版本 1.6)更新到最新的 Mapbox iOS SDK 3.x。

在新版本中,我无法弄清楚如何将 Mapbox MGLMapView 缩放到以公里为单位的给定半径以适应屏幕。

在旧版本(1.6 版)中,RMMapView.zoomWithLatitudeLongitudeBoundsSouthWest 方法的工作如下:

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)
}

如何使用 Swift 在最新的 Mapbox 中实现半径缩放?

最佳答案

现在 -setVisibleCoordinateBounds:animated 将完成这项工作:

Changes the receiver’s viewport to fit the given coordinate bounds, optionally animating the change.

Mapbox iOS SDK Reference

这是一个例子:

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

关于ios - 如何使用 Swift 将 Mapbox 缩放到以千米为单位的给定半径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38946722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com