从 mapView 获取视口坐标? regionDidChanged swift
Get viewport coordinates from mapView? regionDidChanged swift
当用户移动地图时调用以下函数。
可以获取视口吗?视口是 north/east 的经纬度和纬度。和隆。共 south/west.
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.
上找不到任何东西
目的是我使用 google 分析记录坐标,并使用另一个工具评估数据。
有人有想法吗?非常感谢
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)
google地图
mapView 有一个 属性 "projection",您可以在其中使用 "coordinateForPoint" 将点从 mapView 转换为坐标。所以以下可以工作:
swift 3 for google 地图
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 宽度和高度
基于
Swift 3 MapKit
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)
当用户移动地图时调用以下函数。
可以获取视口吗?视口是 north/east 的经纬度和纬度。和隆。共 south/west.
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.
上找不到任何东西目的是我使用 google 分析记录坐标,并使用另一个工具评估数据。
有人有想法吗?非常感谢
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)
google地图
mapView 有一个 属性 "projection",您可以在其中使用 "coordinateForPoint" 将点从 mapView 转换为坐标。所以以下可以工作:
swift 3 for google 地图
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 宽度和高度
基于
Swift 3 MapKit
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)