0

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!

Aderstedt
  • 6,301
  • 5
  • 28
  • 44
Trip Phillips
  • 430
  • 1
  • 5
  • 18

1 Answers1

1

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Yeah I have the GeoPoints already saved. I am doing this in another view controller that allows the user to put in info about an event. Where I have been confused is how I am supposed to call back the GeoPoints I have saved in Parse so that other users can see the event in the map view. – Trip Phillips Jul 03 '15 at 07:02
  • So your query should include the location of the centre of the map view, then you loop over the objects to create annotations at each of their locations – Wain Jul 03 '15 at 11:52