我正在尝试从我的解析后端查询坐标数组(lat和long)。然后将它们用作地图上的注释。虽然我从解析中查询过,但我不确定如何将坐标转换为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
我知道这有点乱,我真的不太确定,因为我还是新手,因为我很快就会努力工作。如果有人可以提供任何帮助,我们将不胜感激。
答案 0 :(得分:2)
假设usersLocation.coordinate
是PFGeoPoint
,您可以使用我为我的某个项目创建的以下扩展程序:
extension PFGeoPoint {
public var cllocation: CLLocation {
get {
return CLLocation(latitude: latitude, longitude: longitude)
}
}
}
然后,以下内容应该有效(location
将是CLLocation
个对象)。
var location = usersLocation.coordinate.cllocation
答案 1 :(得分:0)
做吧!
var local : PFGeoPoint = PFGeoPoint()
if let object = currentObject {
local = object["PFGeoPoint Col Name"] as! PFGeoPoint
}
let getLatParse : CLLocationDegrees = local.latitude
let getLongParse : CLLocationDegrees = local.longitude
let localParse = CLLocation(latitude: getLatParse, longitude: getLongParse)