ios - Adding timestamp to MapView Annotation via Parse? -
this current query setup retrieve data parse , set annotation pin on mapview. take time created , add simple 5:00pm example within annotation well. there way pull time , not date parse through query , set mkannotation?
override func viewdidappear(animated: bool) { var annotationquery = pfquery(classname: "post") currentloc = pfgeopoint(location: mapviewlocationmanager.location) //annotationquery.wherekey("location", neargeopoint: currentloc, withinmiles: 10) annotationquery.wherekeyexists("location") annotationquery.findobjectsinbackgroundwithblock { (points, error) -> void in if error == nil { // find succeeded. println("successful query annotations") // found objects let myposts = points as! [pfobject] post in myposts { let point = post["location"] as! pfgeopoint let annotation = mkpointannotation() annotation.coordinate = cllocationcoordinate2dmake(point.latitude, point.longitude) annotation.title = post["title"] as! string! annotation.subtitle = post["username"] as! string! self.mapview.addannotation(annotation) } } else { // log details of failure println("error: \(error)") } } here photo of parse backend give better idea:
pfobject has "createdat" property. assign nsdate object , need format using nsdateformatter display time component only. untested code you.
post in myposts { let point = post["location"] as! pfgeopoint let annotation = mkpointannotation() annotation.coordinate = cllocationcoordinate2dmake(point.latitude, point.longitude) annotation.title = post["title"] as! string! annotation.subtitle = post["username"] as! string! let formatter = nsdateformatter() formatter.datestyle = nsdateformatterstyle.nostyle formatter.timestyle = .shortstyle let datestring = formatter.stringfromdate(post.createdat) annotation.timetitle /* or equivalent */ = datestring self.mapview.addannotation(annotation) }
Comments
Post a Comment