I'm trying to get saved GeoPoints from Parse in order to create point annotations that can be viewed in the map view. This is my current code:
override func viewDidLoad() {
super.viewDidLoad()
var query = PFQuery(className:"SpotInfo")
query.whereKey("Location", equalTo: PFGeoPoint() )
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void In
if error == nil {
println("Succesfully retrieved objects.")
if let objects = objects as? [PFObjects] {
for object in objects {
println(objects.objectId)
}
}
} else {
println("Error: \(error!)(error!.userInfo!)")
}
let latit = query["Location"].latitude as Double
let longi = query["Location"].longitude as Double
let SpotLoc = CLLocationCoordinate2DMake(latit, longi)
let Spot = MKPointAnnotation()
Spot.coordinate = SpotLoc
Spot.title = "Spot"
Spot.subtitle = "Time"
Map.addAnnotation(Spot)
}
}
In the let latit
and let longi
variables I am getting an error saying
"PFQuery does not have a member named subscript"
What does this mean and how can I fix it? Please help. Thanks!
You seem to be confused on a couple of points.
When you create the geopoint for the query you need to specify the latitude and longitude. You need to get them from somewhere. Your current code creates an empty location. So you need to use a location manager to get the current location / ask the user / hard code it.
When the completion block is called you should be using the objects
returned, not trying to access some information from the query. This is where your current compile error is because the query doesn't offer what you're trying to use it for. Eeach object has a Location
that you should be using in your loop which currently just logs.