通过从Parse获取数据在MKMapKit上显示注释

时间:2015-06-27 06:40:58

标签: swift parse-platform mkmapview

所以我正在尝试使用用户当前位置创建注释。在我将我的应用程序连接到Parse之前,我可以将信息保存到<input type="file" file-model="myFile"/> var fd = new FormData(); fd.append('file', $scope.myFile); $http.post(uploadUrl, fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined} }) .success(function(){ //success }) .error(function(){ //failure }); 并且它工作得很好。现在我正在使用Parse,我无法弄清楚如何在一个视图控制器中调用我在Parse中保存的坐标,这样我就可以在另一个Map View控制器中显示坐标作为注释。我正在使用的当前代码是

NSUserDefaults

那么如何修改此代码以显示我保存到Parse的坐标? 感谢

1 个答案:

答案 0 :(得分:0)

我认为this answer正是您正在寻找的

代码:

        //MARK: (471) Crossing Positions
        //*******************************************************

        let myGeoPoint = PFGeoPoint(latitude: lat, longitude:lon)
        let myParseId = PFUser.currentUser().objectId //PFUser.currentUser().objectId
        var radius = 100.0

        println("****** this is my geoPoint from map view controller: \(myGeoPoint)")


        //MARK: *** let's look for other users ***

        var nearArray : [CLLocationCoordinate2D] = []

        func filterByProximity() {
            PFQuery(className: "Position")
                .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: radius)     //(474)
                .findObjectsInBackgroundWithBlock ({
                    objects, error in
                    if let proximityArray = objects as? [PFObject] {
//                        println("****** here the proximity matches: \(proximityArray)")
                        for near in proximityArray {
//                            println("here they are \(near)")

                            let position = near["where"] as? PFGeoPoint

                            var theirLat = position?.latitude       //this is an optional
                            var theirLong = position?.longitude     //this is an optional
                            var theirLocation = CLLocationCoordinate2D(latitude: theirLat!, longitude: theirLong!)

                            nearArray.append(theirLocation)

                            if nearArray.isEmpty {
                                println("*** ERROR! anyone close by ***")
                            } else
                            {
                                for person in nearArray {

                                    let span = MKCoordinateSpanMake(2.50, 2.50)
                                    let region = MKCoordinateRegionMake(theirLocation, span)
                                    self.mapView.setRegion(region, animated: true)

                                    let theirAnotation = MKPointAnnotation()
                                    theirAnotation.setCoordinate(theirLocation)
                                    theirAnotation.title = near["who"] as String

                                    self.mapView.addAnnotation(theirAnotation)
                                }

                            }



                        }
                        println("****** in a radius of \(radius) there are \(nearArray.count) bikers ******")

                    }
                })
        }

        filterByProximity()