当用户移动地图时,会调用以下函数。
可以获取视口吗?视口是北/东和纬度的经度和纬度。和lon。南/西。
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
}
我不知道如何从我的数据中获取视口。我无法在www。
中找到任何内容目的地是我使用谷歌分析记录坐标,另一个工具评估数据。
有人有想法吗?非常感谢
答案 0 :(得分:8)
<强> 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)
<强> GOOGLEMAPS 强>
mapView有一个属性&#34;投影&#34;在哪里可以使用&#34; coordinateForPoint&#34;将一个点从mapView转换为一个坐标。所以以下方法可行:
swift 3 for google maps
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的宽度和高度
即可答案 1 :(得分:4)
let northEast = mapView.convert(CGPoint(x: mapView.bounds.width, y: 0), toCoordinateFrom: mapView) let southWest = mapView.convert(CGPoint(x: 0, y: mapView.bounds.height), toCoordinateFrom: mapView)