当用户移动 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/