showing GeoPoints from parse.com in MKMapView

1.1k views Asked by At

I'm trying to build an app showing my favorite spots with swift.

I already store my spot information GeoPoints from parse.com. But I still can't manage to show retrieve the data (spot name and GeoPoints) and pass it to MKMapView. Can someone show me an example to do this?

I also find this question Parse objects as AnnonationPoints, but since I just started learning swift, I don't understand about Objective-C.

really appreciate if anyone can help me. Thank you in advance.

1

There are 1 answers

0
Gibran On BEST ANSWER

After googling, and trial and error, this is my best answer right now. Hope helps for others!

   // retrieve data from parse.com
    let query:PFQuery = PFQuery(className: "SpotList")
    query.orderByAscending("SpotName")
    query.findObjectsInBackgroundWithBlock{ (objects:[AnyObject]! , error:NSError!)-> Void in
        if !(error != nil){
            for object in objects!   {
                self.SpotNames.append(object["SpotName"] as String)
                self.SpotGeoPoints.append(object["SpotLocation"] as PFGeoPoint)
                self.SpotLocationLatitudes.append(self.SpotGeoPoints.last?.latitude as CLLocationDegrees!)
                self.SpotLocationLongitudes.append(self.SpotGeoPoints.last?.longitude as CLLocationDegrees!)

                var annotation = MKPointAnnotation()
                annotation.coordinate = CLLocationCoordinate2DMake(self.SpotLocationLatitudes.last!, self.SpotLocationLongitudes.last!)
                annotation.title = self.SpotNames.last!
                self.mainMap.addAnnotation(annotation)
                self.mainMap.showsUserLocation = true
            }
        }
    }