我有一个应用程序,可以在桌面视图中显示可以通过地图上的按钮添加的位置。我无法保存这些解析(是的,我知道它已经退役但我已经设置了一个完全相同的新服务器,所以考虑它是解析的)也注意我已经看过这个主题:https://stackoverflow.com/questions/30435362/how-can-i-send-coordinates-to-parse-and-save-it-as-parse-pfgeopoin t和即使它看起来很简单,它仍然让我感到困惑,所以这是我的tableview中的代码
▒9▒▒w\▒▒XS▒▒S▒▒
以下是广告引脚的代码(在地图视图控制器中)
var places = [Dictionary<String,String>()]
var activePlace = -1
感谢您帮助我使用解析/外部服务器
编辑:我试过这个: @IBAction func addSpot(sender: UIBarButtonItem) {
var newCoordinate2 = self.map.userLocation.location!.coordinate;
var location = CLLocation(latitude: newCoordinate2.latitude, longitude: newCoordinate2.longitude)
//title = "new address"
//try change order start
let annotation = MKPointAnnotation()
self.map.addAnnotation(annotation)
annotation.coordinate = newCoordinate2
annotation.title = title
annotation.coordinate = self.map.userLocation.location!.coordinate;
CLGeocoder().reverseGeocodeLocation(location) { (placemarks, error) -> Void in
var title = ""
if (error == nil) {
if let p = placemarks?[0] {
var subThouroughfare:String = ""
var thouroughfare:String = ""
if p.subThoroughfare != nil {
subThouroughfare = p.subThoroughfare!
}
if p.thoroughfare != nil {
thouroughfare = p.thoroughfare!
}
title = "\(subThouroughfare) \(thouroughfare)"
}
}
if title == "" {
title = "Added \(NSDate())"
}
places.append(["name":title,"lat":"\(newCoordinate2.latitude)","lon":"\(newCoordinate2.longitude)"])
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate2
annotation.title = title
self.map.addAnnotation(annotation)
}
self.map.addAnnotation(annotation);
func mapView(mapView: MKMapView!,
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!{
if(annotation is MKUserLocation){
return nil;
}
// let pinView: Void = mapView.addAnnotation(annotation);
let pinAnnotationView = MKPinAnnotationView(annotation: annotation,reuseIdentifier:"MyIdentifier");
return pinAnnotationView;
}
}
我在三行上出错了 1)实例成员'下标'不能用于'PFObject'类型 2)类型'CLLocation'没有下标成员 3)CLLocation类型的值没有成员'saveInBackgroundWithBlock'
RE EDIT:我已经尝试了这个并收到一条警告,说'返回后的代码永远不会被执行'也会在应用程序上运行但不保存
PFObject["geoPoint"] = PFGeoPoint(location: location)
location[location] = activePlace
location.saveInBackgroundWithBlock { (succes, error) -> Void in
print("place has been saved")
}
答案 0 :(得分:1)
所以你需要一些东西来包含你的PFGeoPoint
,那个东西需要是PFObject
。在解析后端,您可以为此对象创建表,并使用对geoPoint的引用以及您想要的任何其他内容进行设置。现在,您可以使用表的类名为每个新点实例化PFObject
,设置对geoPoint的引用(使用pfObject["geoPoint"] = geoPoint
),保存(使用pfObject.saveInBackgroundWithBlock...
)并且您&# 39;重新完成。