ios - 从 mapView 获取视口(viewport)坐标? regionDidChanged swift

标签 ios swift google-analytics android-mapview viewport

当用户移动 map 时调用以下函数。

可以获取视口(viewport)吗?视口(viewport)是北/东和纬度的纬度和经度。和隆。南/西。

 func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool){
    print("The \(mapView.centerCoordinate)")
    print("the maprect \(mapView.visibleMapRect.origin)")
    print("the maprect \(mapView.visibleMapRect.size)")
    //I find just this attributes for mapView

    }

我不知道如何从我的数据中获取视口(viewport)。我在 www 上找不到任何东西。

目标是我使用谷歌分析记录坐标,并使用另一个工具评估数据。

有人有想法吗?非常感谢

最佳答案

MapKit

let northEast = mapView.convertPoint(CGPoint(x: mapView.bounds.width, y: 0), toCoordinateFromView: mapView)
let southWest = mapView.convertPoint(CGPoint(x: 0, y: mapView.bounds.height), toCoordinateFromView: mapView)

谷歌地图

mapView 有一个属性“projection”,您可以在其中使用“coordinateForPoint”将点从 mapView 转换为坐标。所以以下可以工作:

谷歌地图的 swift 3

let northEast = mapView.projection.coordinate(for: CGPoint(x: mapView.layer.frame.width, y: 0))
let southWest = mapView.projection.coordinate(for: CGPoint(x: 0, y: mapView.layer.frame.height))

swift 2

let northEast = mapView.projection.coordinateForPoint(CGPoint(x: mapWidth, y: 0 ))
let southWest = mapView.projection.coordinateForPoint(CGPoint(x: 0, y: mapHeight))

你只需要输入你的mapView宽度和高度

关于ios - 从 mapView 获取视口(viewport)坐标? regionDidChanged swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36476163/

相关文章:

ios - 在标签栏 Controller 中查看 Controller

android - fontSize 在 Unity 中究竟意味着什么?

ios - 如何获取数组中的字典对象

firebase - 当可以通过Firebase控制台创建项目时,采用最新的App + Web属性的目的是什么?

ios - 优化 iPhone 6/6+ 屏幕的 Interface Builder 更新

objective-c - 自定义UI分段控件

ios - 我怎样才能从图像中分离出边界?

arrays - 在单个循环中更新多个累加器时遇到问题

ios - Pod 库中的 Google Analytics Track Screen(UIViewController)

google-analytics - 推荐人会影响 GA 跟踪吗?