Swift:如何知道谷歌地图的右上角和左下角坐标

Dan*_*ani 5 google-maps bounding-box ios swift

每次移动相机时,我都需要知道谷歌地图中的右上角和左下角坐标.API为我提供了相机的中心点.有没有办法通过API或某些算法知道中心点(目标),缩放和方位来获得我想要的东西?

func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
    position.target
    position.zoom
    position.bearing

}
Run Code Online (Sandbox Code Playgroud)

Der*_*ike 9

斯威夫特3

使用GMSProjectionvisibleRegion方法.

let projection = mapView.projection.visibleRegion()

let topLeftCorner: CLLocationCoordinate2D = projection.farLeft
let topRightCorner: CLLocationCoordinate2D = projection.farRight
let bottomLeftCorner: CLLocationCoordinate2D = projection.nearLeft
let bottomRightCorner: CLLocationCoordinate2D = projection.nearRight
Run Code Online (Sandbox Code Playgroud)

看看这个问题吧.


Rey*_*cia 3

如何知道谷歌地图的右上角和左下角坐标

在iOs Maps Reference 上发现这个GMSCoordinateBounds表示地球表面上的矩形边界框。它具有边界框的东北和西南属性。

  • (id) initWithCooperative: (CLLocationCooperative2D) coord1 坐标: (CLLocationCooperative2D) coord2 初始化与两个角定义的矩形区域相对应的东北和西南边界。盒子的经度是否从 coord1 延伸到 coord2 或反之亦然是不明确的;

检查此Github 存储库,了解有关如何在代码中使用它的更多信息。