我正在尝试使用swift构建一个显示我最喜欢的广告的应用。
我已经从parse.com存储了我的现场信息GeoPoints。但我仍然无法显示检索数据(地点名称和GeoPoints)并将其传递给MKMapView。有人能告诉我一个例子来做这件事吗?
我也发现了这个问题Parse objects as AnnonationPoints,但由于我刚开始学习swift,我不了解Objective-C。
答案 0 :(得分:2)
谷歌搜索和试错后,这是我现在最好的答案。希望有助于其他人!
// retrieve data from parse.com
let query:PFQuery = PFQuery(className: "SpotList")
query.orderByAscending("SpotName")
query.findObjectsInBackgroundWithBlock{ (objects:[AnyObject]! , error:NSError!)-> Void in
if !(error != nil){
for object in objects! {
self.SpotNames.append(object["SpotName"] as String)
self.SpotGeoPoints.append(object["SpotLocation"] as PFGeoPoint)
self.SpotLocationLatitudes.append(self.SpotGeoPoints.last?.latitude as CLLocationDegrees!)
self.SpotLocationLongitudes.append(self.SpotGeoPoints.last?.longitude as CLLocationDegrees!)
var annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(self.SpotLocationLatitudes.last!, self.SpotLocationLongitudes.last!)
annotation.title = self.SpotNames.last!
self.mainMap.addAnnotation(annotation)
self.mainMap.showsUserLocation = true
}
}
}