【发布时间】:2015-05-05 22:47:04
【问题描述】:
我正在用 Swift 编写一个应用程序,并使用 Parse 作为后端。
为了设置对 Parse 的查询,我想获取当前 MKMapView 上显示的最西南点和最东北点。
我目前得到的这些值如下所示:
//___ To calculate the search bounds, first we need to calculate the corners of the map
let nePoint = CGPointMake(self.myMap.bounds.origin.x + myMap.bounds.size.width, myMap.bounds.origin.y);
let swPoint = CGPointMake((self.myMap.bounds.origin.x), (myMap.bounds.origin.y + myMap.bounds.size.height));
//___ Then transform those point into lat, lng values
let neCoord = myMap.convertPoint(nePoint, toCoordinateFromView: myMap)
let swCoord = myMap.convertPoint(swPoint, toCoordinateFromView: myMap)
let neGP = PFGeoPoint(latitude: neCoord.latitude, longitude: neCoord.longitude)
let swGP = PFGeoPoint(latitude: swCoord.latitude, longitude: swCoord.longitude)
var query = PFQuery(className: "locations")
//___ Limit what could be a lot of points.
query.limit = 25
query.whereKey("location", withinGeoBoxFromSouthwest: swGP, toNortheast: neGP)
这在地图旋转之前完美运行。
但是,一旦用户旋转地图,右上角和左下角的点不再代表最东北和最西南的点。
如何始终计算地图上显示的真正的最西南和最东北的点?
谢谢。
【问题讨论】: