我的目标是将视图的左上角和右下角转换为纬度/经度坐标.这些lat/lon坐标将用于查询仅存在于视图中的注释位置(不是全部5000+).
我在Stackoverflow上找到了这个Objective-C技巧.但我遇到的问题是它正在从mapView转换0,0(纬度/经度为-180,-180.Aka,南极).
所以代替:
topLeft = mapView.convertPoint(CGPointMake(0, 0), toCoordinateFromView: self.mapView)
Run Code Online (Sandbox Code Playgroud)
我想我可以做到:
topLeft = view.convertPoint(CGPointMake(0, 0), toCoordinateFromView: self.mapView)
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
无法使用类型'(CGPoint,toCoordinateFromView:MKMapView!)的参数列表调用'convertPoint'
我花了一天时间试图解决这个问题,但无济于事,我来找你寻求指导.任何帮助将非常感激.
这是完整的功能:
func findCornerLocations(){
var topLeft = CLLocationCoordinate2D()
let mapView = MKMapView()
topLeft = view.convertPoint(CGPointMake(0, 0), toCoordinateFromView: self.mapView)
print(topLeft.latitude, topLeft.longitude)
}
Run Code Online (Sandbox Code Playgroud)