![](/img/trans.png)
[英]Error converting CLLocationCoordinate2D to CLLocation in Swift
[英]Converting Parse GeoPoint into a CLLocation in Swift
我在Swift公司工作。
在我的Parse后端中,我有一个名为location的键,它具有许多geoPoint值,其中包括纬度和经度点。 我想查询/获取所有这些点并将它们放置在数组中,以便随后将它们用作地图上的不同注释。
我在查询位置时遇到麻烦,因此它们可以用作地图的CLLocation。
如果有人可以帮助我做到这一点,将不胜感激。
您可以创建一个变量作为PFGeoPoint,并将解析后的数据放入该变量中:
var descLocation: PFGeoPoint = PFGeoPoint()
var innerP1 = NSPredicate(format: "ObjectID = %@", objectID)
var innerQ1:PFQuery = PFQuery(className: "Test", predicate: innerP1)
var query = PFQuery.orQueryWithSubqueries([innerQ1])
query.addAscendingOrder("createdAt")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
descLocation = object["GeoPoint"] as PFGeoPoint
}
} else {
println("Error")
}
}
在需要位置的班级中,只需添加以下行:
var latitude: CLLocationDegrees = descLocation.latitude
var longtitude: CLLocationDegrees = descLocation.longitude
var location: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude, longitude: longtitude)
因此,您可以使用以下代码向地图添加注释:
@IBOutlet var map: MKMapView!
var annotation = MKPointAnnotation()
annotation.title = "Test"
annotation.coordinate = location
map.addAnnotation(annotation)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.