ios - Query a GeoPoint from Parse and add it to MapKit as MKAnnotation? -


i trying query array of pfgeopoints stored on parse backend. have pfobject in parse called "post", data assigned such "location", "title", "message", etc.

everything being sent parse upon posting app , stored in backend. having issues retrieving properties of "post" pfobject parse , storing them mkannotation on map.

here mapviewviewcontroller:

import uikit import parse import corelocation import mapkit  class mapviewviewcontroller: uiviewcontroller, mkmapviewdelegate, cllocationmanagerdelegate {  @iboutlet var mapview: mkmapview!  var mapviewlocationmanager:cllocationmanager! = cllocationmanager() var currentloc: pfgeopoint! = pfgeopoint()  var posttitle: string! var postbody: string!   override func viewdidload() {     super.viewdidload()     mapview.showsuserlocation = true     mapview.delegate = self     mapviewlocationmanager.delegate = self     mapviewlocationmanager.startupdatinglocation()     mapview.setusertrackingmode(mkusertrackingmode.follow, animated: true) }  override func viewdidappear(animated: bool) {     var annotationquery = pfquery(classname: "post")     currentloc = pfgeopoint(location: mapviewlocationmanager.location)     annotationquery.wherekey("location", neargeopoint: currentloc, withinmiles: 10)     annotationquery.findobjectsinbackgroundwithblock {         (points, error) -> void in         if error == nil {             // find succeeded.             println("successful query annotations")             // found objects             //this lost parse query/adding annotation map               //the following code prints correct postcount stored in parse             println("total posts: \(points?.count)")          } else {             // log details of failure             println("error: \(error)")         }     }  }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  @ibaction func logoutbutton(sender: uibarbuttonitem) {     pfuser.logout()     dismissviewcontrolleranimated(true, completion: nil) }  @ibaction func newpostbutton(sender: anyobject) {     performseguewithidentifier("maintonewpost", sender: self) } 

i query , retrieve post of info entered user (pfgeopoint, title, body) , turn mkannotation on map.

here photo of parse backend give better idea:

http://i1249.photobucket.com/albums/hh512/zachkhan3/screen%20shot%202015-04-22%20at%2012.39.42%20pm.png

from screenshot provided, assume querying post object pfobject. can access each post object in returned posts array. can use location property each post object, , add annotation mapview.

annotationquery.findobjectsinbackgroundwithblock {         (posts, error) -> void in         if error == nil {             // find succeeded.             println("successful query annotations")             let myposts = posts [pfobject]              post in myposts {                 let point = post["location"] pfgeopoint                 let annotation = mkpointannotation()                 annotation.coordinate = cllocationcoordinate2dmake(point.latitude, point.longitude)                 self.mapview.addannotation(annotation)             }         } else {             // log details of failure             println("error: \(error)")         }     } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -