【问题标题】:Swift: How to know the top right and bottom left coordinates of a google mapSwift:如何知道谷歌地图的右上角和左下角坐标
【发布时间】:2016-10-18 03:10:00
【问题描述】:

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

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

}

【问题讨论】:

    标签: ios swift google-maps bounding-box


    【解决方案1】:

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

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

    • (id) initWithCoordinate: (CLLocationCoordinate2D) coord1 坐标: (CLLocationCoordinate2D) coord2 初始化东北和西南 边界对应于由两个定义的矩形区域 角落。盒子的经度是否从 coord1 到 coord2,反之亦然;

    查看此Github repo 以获取有关如何在您的代码中使用它的更多信息。

    【讨论】:

    • 其实我需要从mapView或者camera获取那些GMSCoordinateBounds。但我找不到如何获得它们。有创建带边界的相机的功能,但是我不需要创建相机,我需要获取现有相机的边界!
    【解决方案2】:

    斯威夫特 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
    

    也可以看看this question

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 2013-12-22
      • 2021-10-30
      • 1970-01-01
      • 2018-12-29
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多