swift - Convert PFGeopoint lat and long from Parse to display current users distance in radius to other users onto a text label -


result page not showing distance

the first image example of result returning , second image example of results page, 'distance' label need change in order display users distance. have users locations stored on parse pfgeopoint called "location" in lat , long. have tabelviewcell textlabel. users shown on vc , trying show how far these users current user in tinder.

i have other users locations running in logs lat , long coordinates , have text label updating "distance" "[] km away!" must getting array returning empty.

i have searched internet , can't seem figure out. tutorials obj c or json or add annotations in mapview. here code on usersresultsviewcontroller:

var locationmanager : cllocationmanager!  var latitude: cllocationdegrees = 0 var longitude: cllocationdegrees = 0  @ibaction func done(sender: uibarbuttonitem) {     self.performseguewithidentifier("backtoprofile", sender: self)  }  @iboutlet var resultspagetableview: uitableview!  var imagefiles = [pffile]() var instrumenttext = [string]() var nametext = [string]() var agetext = [string]() var locationtext = [pfgeopoint]() 

var userslocations = double

let roundedtwodigitdistance = double

override func viewdidload() {     super.viewdidload()      locationmanager = cllocationmanager()     locationmanager.delegate = self     locationmanager.desiredaccuracy = kcllocationaccuracybest     locationmanager.requestwheninuseauthorization()     locationmanager.startupdatinglocation()      // start of tableview: let query = pfquery(classname: "_user")     query.wherekey("username", notequalto:pfuser.currentuser()!.username!)     query.findobjectsinbackgroundwithblock { (users: [anyobject]?, error: nserror?) -> void in  if error == nil { // success  print(users!.count) user in users! { self.imagefiles.append(user["image"] as! pffile) self.instrumenttext.append(user["instrument"] as! string) self.nametext.append(user["name"] as! string) self.agetext.append(user["age"] as! string) // self.locationtext.append(user["location"] as! pfgeopoint)  } // reload table forget load nothing       self.resultspagetableview.reloaddata()  } else {     print("error")     }     }     } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {      // *** note self: return here must mandatory field user @ again nd change mandatory age or username or something.      return imagefiles.count }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let singlecell: customcell = tableview.dequeuereusablecellwithidentifier("mysinglecellid") as! customcell      // text     singlecell.usersinstrument.text = instrumenttext[indexpath.row]     singlecell.username.text = nametext[indexpath.row]     singlecell.userage.text = agetext[indexpath.row]  let query = pfuser.query()!      if let latitude = pfuser.currentuser()?["location"]?.latitude {          if let longitude = pfuser.currentuser()?["location"]?.longitude {              print(latitude)             print(longitude)              query.wherekey("username", notequalto:pfuser.currentuser()!.username!)             query.wherekey("location", withingeoboxfromsouthwest: pfgeopoint(latitude: latitude - 10, longitude: longitude - 10), tonortheast:pfgeopoint(latitude:latitude + 10, longitude: longitude + 10))              query.findobjectsinbackgroundwithblock { (users: [anyobject]?, error: nserror?) -> void in                  if error == nil {                     // success                      user in users! {          singlecell.userdistance.text = "\(self.locationtext) km away!" 

here of forums have found helpful still stuck!!!:

http://www.scriptscoop.com/t/a2d00e357960/ios-converting-a-pfgeopoint-lat-and-long-from-parse-into-a-cllocation-lat-.html trying access subscript of parse query array in swift two query constraints on 1 key parse , swift

pfgeopoints have methods called "distanceinmilesto:" , "distanceinkilometersto:". these you're going want use. call method on pfgeopoint storing current user's location, , pass in each user's location query. store result in appropriate label.

here link api reference method: http://parse.com/docs/ios/api/classes/pfgeopoint.html#//api/name/distanceinkilometersto:


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -