因此,我正在设置这个应用程序,用户可以看到他们的位置,也能够看到其他人的立场。我跟着这个问题来写剧本。how to retrive location from a PFGeopoint - (Parse.com and Swift) and show it on the map with Xcode 6.2
在编写代码时,在这一行中出现了一个错误:
if let proximityArray = objects as? [PFObject] {说:
来自“DownCast?”的PFObject?只有“PFObject”才能解开选项:你是指使用“!”吗?
所以我试着补充:
for object in objects as! [PFObject]{不过,我还是会犯同样的错误。
老实说,我不知道这些东西是什么。
我不知道如何解决这个问题,如果能为解决这个问题提供任何帮助,我将不胜感激。
谢谢
对于那些想要其余代码的人,下面是:
func filterByProximity() {
PFQuery(className: "location")
.whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0) //(474)
.findObjectsInBackgroundWithBlock ({
objects, error in
for object in objects as! [PFObject]{
if let proximityArray = objects as? [PFObject] {
print("****** here the proximity matches: \(proximityArray)")
for near in proximityArray {
println("here they are \(near)")
if let position = near["where"] as! PFGeoPoint {
let theirLat = position.latituide
let theirLon = position.longitude
}
let theirLat = near["where"].latitude as Double
let theirlong = near["where"].longitude as Double
let location = CLLocationCoordinate2DMake(theirLat, theirlong)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(location, span)
self.MapView?.setRegion(region, animated: true)
let theirAnotation = MKPointAnnotation()
theirAnotation.setCoordinate(location)
self.mapView.addAnnotation(anotation)
}
}
}
})
}
filterByProximity()发布于 2016-01-14 15:56:40
请将您的代码更改为以下代码:
func filterByProximity() {
PFQuery(className: "location")
.whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0) //(474)
.findObjectsInBackgroundWithBlock ({
objects, error in
if let objects = objects {
for object in objects{
let proximityArray = objects
print("****** here the proximity matches: \(proximityArray)")
for near in proximityArray {
println("here they are \(near)")
if let position = near["where"] as? PFGeoPoint {
let theirLat = position.latituide
let theirLon = position.longitude
}
let theirLat = near["where"].latitude as Double
let theirlong = near["where"].longitude as Double
let location = CLLocationCoordinate2DMake(theirLat, theirlong)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(location, span)
self.MapView?.setRegion(region, animated: true)
let theirAnotation = MKPointAnnotation()
theirAnotation.setCoordinate(location)
self.mapView.addAnnotation(anotation)
}
}
})
}
filterByProximity()这样就可以消除选项词的错误。但是我认为您的代码中有一个逻辑错误,应该是这样的:
func filterByProximity() {
PFQuery(className: "location")
.whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0) //(474)
.findObjectsInBackgroundWithBlock ({
objects, error in
if let proximityArray = objects {
print("****** here the proximity matches: \(proximityArray)")
for near in proximityArray {
println("here they are \(near)")
if let position = near["where"] as? PFGeoPoint {
let theirLat = position.latituide
let theirLon = position.longitude
}
let theirLat = near["where"].latitude as Double
let theirlong = near["where"].longitude as Double
let location = CLLocationCoordinate2DMake(theirLat, theirlong)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(location, span)
self.MapView?.setRegion(region, animated: true)
let theirAnotation = MKPointAnnotation()
theirAnotation.setCoordinate(location)
self.mapView.addAnnotation(anotation)
}
}
})
}
filterByProximity()https://stackoverflow.com/questions/34793868
复制相似问题