如何使用Google Maps SDK使GMSCircle的边界完全显示在地图上?

Aas*_*aug 2 iphone xcode objective-c ios

我想完全显示GMSCircle在MapView上,但radius圆的动态变化。什么时候radius改变MapView将自动调整到地图上查看完整的圆圈,以显示所有标志。

Swift语言上,我找到了一个可能对我有帮助的解决方案,如下所示:基于Radius Google Maps iOS SDK更改相机缩放

但是我必须实现这一点,Objective-c并且Objective-c我们没有绑定属性GMSCircle

在此先感谢,请指导我。

soh*_*ani 5

对于SWIFT 3

只需将此扩展添加到您的项目中:

import GoogleMaps
extension GMSCircle {
    func bounds () -> GMSCoordinateBounds {
        func locationMinMax(positive : Bool) -> CLLocationCoordinate2D {
            let sign:Double = positive ? 1 : -1
            let dx = sign * self.radius  / 6378000 * (180/M_PI)
            let lat = position.latitude + dx
            let lon = position.longitude + dx / cos(position.latitude * M_PI/180)
            return CLLocationCoordinate2D(latitude: lat, longitude: lon)
        }

        return GMSCoordinateBounds(coordinate: locationMinMax(positive: true),
                                   coordinate: locationMinMax(positive: false))
    }
}
Run Code Online (Sandbox Code Playgroud)

将此文件添加到您的项目后,您要做的就是:

let update = GMSCameraUpdate.fit(self.cirlce.bounds())
self.mapView.animate(with: update)
Run Code Online (Sandbox Code Playgroud)