gpt4 book ai didi

ios - 谷歌地图半径缩放级别

转载 作者:行者123 更新时间:2023-11-28 06:13:44 24 4
gpt4 key购买 nike

我有一张 map ,上面有一个自定义 UIView。我正在根据缩放级别计算圆的半径。

func getCenterCoordinate() -> CLLocationCoordinate2D {
let centerPoint = self.mapView.center
let centerCoordinate = self.mapView.projection.coordinate(for: centerPoint)
return centerCoordinate
}

func getTopCenterCoordinate() -> CLLocationCoordinate2D {
// to get coordinate from CGPoint of your map
let topCenterCoor = self.mapView.convert(CGPoint(x:self.circleView.frame.size.width / 2.0, y:0), from: self.circleView)
let point = self.mapView.projection.coordinate(for: topCenterCoor)
return point
}

func getRadius() -> CLLocationDistance {

let centerCoordinate = getCenterCoordinate()
// init center location from center coordinate
let centerLocation = CLLocation(latitude: centerCoordinate.latitude, longitude: centerCoordinate.longitude)
let topCenterCoordinate = self.getTopCenterCoordinate()
let topCenterLocation = CLLocation(latitude: topCenterCoordinate.latitude, longitude: topCenterCoordinate.longitude)

let radius = CLLocationDistance(centerLocation.distance(from: topCenterLocation)) / 1000
print(radius)
return round(radius)
}

现在,我想根据给定的半径缩放 map ?我该怎么做?

Image1

最佳答案

在圆的周长上选取任意坐标,并将 map 的缩放或相机的缩放设置为该坐标的边界,当然还要添加一些填充。现在对于这个逻辑,如果您的 map 允许用户缩放,则每次您的 map 相机移动或重新居中时,您都必须重新计算。

您可以使用此方法:mapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds, withPadding: 50.0))

这里的 bounds 是一个 GMSCoordinateBounds 对象。

希望对你有帮助

关于ios - 谷歌地图半径缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45733492/

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