Query a GeoPoint from Parse and add it to MapKit as MKAnnotation?

末鹿安然 提交于 2019-11-30 16:23:00

From the screenshot you provided, I assume you are querying the Post object which is a PFObject. So you can access each post object in from the returned posts array. Then you can use the Location property from each post object, and add annotation to your mapView.

annotationQuery.findObjectsInBackgroundWithBlock {
        (posts, error) -> Void in
        if error == nil {
            // The find succeeded.
            println("Successful query for annotations")
            let myPosts = posts as [PFObject]

            for post in myPosts {
                let point = post["Location"] as PFGeoPoint
                let annotation = MKPointAnnotation()
                annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
                self.mapView.addAnnotation(annotation)
            }
        } else {
            // Log details of the failure
            println("Error: \(error)")
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!