qetinac qetinac - 1 year ago 78
iOS Question

Parse Location of other User (swift)

im trying to build an app with parse where i can see location of other user - I know username of my friend and i want to get his last saved location (GeoPoint). This documentation didnt help me: https://www.parse.com/docs/ios/guide#queries

enter image description here

Could u give me example code how can I get GeoPoint of this user from parse when i know his username?


Answer Source

You'd ideally perform a query for the users, then if the user's username is equal to the string you want you can grab their location value via the location key.

Something like this... but play around with it.

let query = PFUser.query()

query.whereKey("Username", equalTo:"TheUsernameYouWantToGetLocationOf")

query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]!, error:NSError!) -> Void in

     if error != nil {
      //print error

    for object in objects  {

       if let geoPoint = object["GeoPoint"] as? PFGeoPoint {

       //then convert to cllocation here...