我正在尝试使用Parse和Swift完成this。
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var latitude:Double = 0.0
var longitude:Double = 0.0
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(true , animated: true)
self.map.showsUserLocation = true
self.map.delegate = self
PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint:PFGeoPoint?, error:NSError?) -> Void in
var query = PFQuery(className: "Locations")
query.whereKey("geopoint", nearGeoPoint: geopoint!)
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let myObjects = objects {
for object in myObjects {
var thePoint: PFGeoPoint = object["geopoint"] as! PFGeoPoint
self.latitude = thePoint.latitude
self.longitude = thePoint.longitude
NSLog(" Hej %f, %f", self.latitude, self.longitude)
var annotationCoordinate: CLLocationCoordinate2D = CLLocationCoordinate2DMake(self.latitude, self.longitude)
var annotation = MKPointAnnotation()
annotation.coordinate = annotationCoordinate
annotation.title = object["discovery"] as! String
annotation.subtitle = object["location"] as! String
self.map.addAnnotation(annotation)
}
}
}
}
}
大图虽然,我正在尝试创建一种方法来访问存储在Parse(及其位置)上的图片,如果他们符合我的查询,则将它们显示在地图上。我非常感谢任何帮助!
答案 0 :(得分:0)
如果您在
中收到转换错误var thePoint: PFGeoPoint = object["geopoint"]
将其更改为
var thePoint: PFGeoPoint = object["geopoint"] as! PFGeoPoint
关于将Double转换为Int,它看起来像你发现的那样,但我不知道swift设计师决定背后的理由。我想了解为什么需要转换,因为可能有替代实现