ios - how to retrive location from a PFGeopoint - (Parse.com and Swift) and show it on the map with Xcode 6.2 -


there answer on this, related different problems , in objective-c. save in parse class "position" positions of users this:

var locationmanager = cllocationmanager()  var lat = locationmanager.location.coordinate.latitude var lon = locationmanager.location.coordinate.longitude  let mygeopoint = pfgeopoint(latitude: lat, longitude:lon) let myparseid = pfuser.currentuser().objectid //pfuser.currentuser().objectid  println("****** geopoint: \(mygeopoint)")  func sendposition(userofposition: user) {  let takeposition = pfobject(classname: "position")   takeposition.setobject(myparseid, forkey: "who") //who  takeposition.setobject(mygeopoint, forkey: "where")                                         takeposition.saveinbackgroundwithblock(nil)                                  }     sendposition(currentuser()!) 

so result: enter image description here

then want show them on map, how? don't understand how retrive latitude , longitude "where" column code below doesn't work:

   import uikit     import mapkit      class mapviewcontroller: uiviewcontroller {       @iboutlet weak var mapview: mkmapview!      var locationmanager : cllocationmanager!       override func viewdidload() {         super.viewdidload()          // additional setup after loading view.            var locationmanager = cllocationmanager()          var lat = locationmanager.location.coordinate.latitude         var lon = locationmanager.location.coordinate.longitude          let location = cllocationcoordinate2d(latitude: lat, longitude: lon)         let span = mkcoordinatespanmake(0.05, 0.05)         let region = mkcoordinateregionmake(location, span)         mapview.setregion(region, animated: true)          let anotation = mkpointannotation()         anotation.setcoordinate(location)         anotation.title = "my title"         anotation.subtitle = " subtitle"          mapview.addannotation(anotation)          println("****** welcome in mapviewcontroller")            //mark: (471) crossing positions         //*******************************************************          let mygeopoint = pfgeopoint(latitude: lat, longitude:lon)         let myparseid = pfuser.currentuser().objectid //pfuser.currentuser().objectid          println("****** geopoint map view controller: \(mygeopoint)")   //         //        var inspector = pfquery(classname:"gamescore") //                inspector.saveinbackgroundwithblock { //                    (success: bool, error: nserror?) -> void in //                    if (success) { //                        // object has been saved. //                        var = inspector.objectid //                    } else { //                        // there problem, check error.description //                    } //                } //         //         //                   func filterbyproximity() {             pfquery(classname: "position")                 .wherekey("where", neargeopoint: mygeopoint, withinkilometers: 500.0)     //(474)             .findobjectsinbackgroundwithblock ({                 objects, error in                 if let proximityarray = objects as? [pfobject] {                     println("****** here proximity matches: \(proximityarray)")                     near in proximityarray {                         println("here \(near)")                         if let position = near["where"] as! pfgeopoint {                         let theirlat = position.latituide                         let theirlon = position.longitude                     }                          let theirlat = near["where"].latitude double                         let theirlong = near["where"].longitude double                         let location = cllocationcoordinate2dmake(theirlat, theirlong)                         let span = mkcoordinatespanmake(0.05, 0.05)                         let region = mkcoordinateregionmake(location, span)                         self.mapview.setregion(region, animated: true)                         let theiranotation = mkpointannotation()                         theiranotation.setcoordinate(location)                         self.mapview.addannotation(anotation)                      }                 }             })         }          filterbyproximity()   //        //update position //         //        func exists() { //        pfquery(classname:"position") //            .wherekey("who", containsstring: myparseid) //            .findobjectsinbackgroundwithblock({ //            thisobject, error in //                if let result = thisobject as? [pfobject] { //                    println("here result: \(result)") //                     //                    let gottheid = result[0].objectid //                    println("ecco l'id singolo \(gottheid)") // //                            //******** update function ******** //                            var query = pfquery(classname:"position") //                            query.getobjectinbackgroundwithid(gottheid) { //                                (usingobject: pfobject?, error: nserror?) -> void in //                                if error != nil { //                                    println(error) //                                } else if let objecttoupdate = usingobject { //                                    println("else occurred") //                                    objecttoupdate["where"] = mygeopoint //                                    println("position should updated") //                                    objecttoupdate.saveinbackgroundwithblock(nil) //                                    println("position should saved") // //                                } //                            } //                            //******** end update function ******** //                } //            }) //        } //         //        exists()          //*******************************************************         }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }     } 

update after first answers

tried check optionals, have message:enter image description here after not down casting double: enter image description here enter image description here

the 'where' pfgeopoint, can call latitude , longitude on them

try - i'm not 100% sure in swift syntax, yet

if(geopoint) {    if(geopoint!.latitude)    {        let latitude = geopoint!.latitude double;    }  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -