首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从[PFObject]下降到[PFObject]

从[PFObject]下降到[PFObject]
EN

Stack Overflow用户
提问于 2016-01-14 15:51:36
回答 1查看 60关注 0票数 1

因此,我正在设置这个应用程序,用户可以看到他们的位置,也能够看到其他人的立场。我跟着这个问题来写剧本。how to retrive location from a PFGeopoint - (Parse.com and Swift) and show it on the map with Xcode 6.2

在编写代码时,在这一行中出现了一个错误:

代码语言:javascript
复制
  if let proximityArray = objects as? [PFObject] {

说:

来自“DownCast?”的PFObject?只有“PFObject”才能解开选项:你是指使用“!”吗?

所以我试着补充:

代码语言:javascript
复制
 for object in objects as! [PFObject]{

不过,我还是会犯同样的错误。

老实说,我不知道这些东西是什么。

我不知道如何解决这个问题,如果能为解决这个问题提供任何帮助,我将不胜感激。

谢谢

对于那些想要其余代码的人,下面是:

代码语言:javascript
复制
func filterByProximity() {
            PFQuery(className: "location")
                .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)     //(474)
                .findObjectsInBackgroundWithBlock ({
                    objects, error in

                    for object in objects as! [PFObject]{

                    if let proximityArray = objects as? [PFObject] {

                        print("****** here the proximity matches: \(proximityArray)")
                        for near in proximityArray {
                            println("here they are \(near)")
                            if let position = near["where"] as! PFGeoPoint {
                                let theirLat = position.latituide
                                let theirLon = position.longitude
                            }

                            let theirLat = near["where"].latitude as Double
                            let theirlong = near["where"].longitude as 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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-14 15:56:40

请将您的代码更改为以下代码:

代码语言:javascript
复制
func filterByProximity() {
        PFQuery(className: "location")
            .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)     //(474)
            .findObjectsInBackgroundWithBlock ({
                objects, error in

                if let objects = objects {
                   for object in objects{

                 let proximityArray = objects 

                    print("****** here the proximity matches: \(proximityArray)")
                    for near in proximityArray {
                        println("here they are \(near)")
                        if let position = near["where"] as? PFGeoPoint {
                            let theirLat = position.latituide
                            let theirLon = position.longitude
                        }

                        let theirLat = near["where"].latitude as Double
                        let theirlong = near["where"].longitude as 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()

这样就可以消除选项词的错误。但是我认为您的代码中有一个逻辑错误,应该是这样的:

代码语言:javascript
复制
func filterByProximity() {
    PFQuery(className: "location")
        .whereKey("where", nearGeoPoint: myGeoPoint, withinKilometers: 5000.0)     //(474)
        .findObjectsInBackgroundWithBlock ({
            objects, error in

            if let proximityArray = objects {

                print("****** here the proximity matches: \(proximityArray)")
                for near in proximityArray {
                    println("here they are \(near)")
                    if let position = near["where"] as? PFGeoPoint {
                        let theirLat = position.latituide
                        let theirLon = position.longitude
                    }

                    let theirLat = near["where"].latitude as Double
                    let theirlong = near["where"].longitude as 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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34793868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档