我正在尝试从解析后端查询坐标数组(纬度和经度)。然后将它们用作 map 上的注释。虽然一旦我从解析中查询,我不知道如何将坐标转换为 CLLocation。
查询时使用的代码:
var usersLocations = [Double]()
override func viewDidLoad() {
super.viewDidLoad()
PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint: PFGeoPoint!, error: NSError!) -> Void in
var query = PFUser.query()
query.whereKey("location", nearGeoPoint: geopoint, withinMiles: 1)
query.limit = 10
var users = query.findObjects()
for user in users {
self.usersLocations.append(user["location"] as Double)
}
self.currentUsersPoint()
}
}
然后是用于尝试将坐标数组放入 CLLocation 的代码。
var latitude:CLLocationDegrees = usersLocation.coordinate.latitude
var longitude:CLLocationDegrees = usersLocation.coordinate.longitude
我知道这有点困惑,我真的不确定,因为我对 swift 和编程还是新手,所以很难解决这一切。如果有人能提供帮助,我们将不胜感激。
最佳答案
假设 usersLocation.coordinate
是 PFGeoPoint
,您可以使用我为我的项目之一创建的以下扩展:
extension PFGeoPoint {
public var cllocation: CLLocation {
get {
return CLLocation(latitude: latitude, longitude: longitude)
}
}
}
然后,以下内容应该可以工作(location
将是一个 CLLocation
对象)。
var location = usersLocation.coordinate.cllocation
关于ios - 快速将 PFGeoPoint 纬度和经度从解析转换为 CLLocation 纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27756940/