我有一个应用程序显示可以通过地图上的按钮添加一个tableview中的位置。我有麻烦保存这些解析(是的,我知道它正在退休,但我已经建立了一个新的服务器,工作完全相同,所以认为它是解析)还请注意我看过这个主题:https://stackoverflow.com/questions/30435362/how-can-i-send-coordinates-to-parse-and-save-it-as-parse-pfgeopoin吨,即使它看起来很简单,它仍然有我困惑所以这里是我的代码在我的tableview如何将位置(引脚)保存到解析服务器?
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;
}
}
谢谢您帮助的我是使用解析/外部服务器的新手
编辑:我曾尝试这样的:
PFObject["geoPoint"] = PFGeoPoint(location: location)
location[location] = activePlace
location.saveInBackgroundWithBlock { (succes, error) -> Void in
print("place has been saved")
}
我上三行 1)实例成员“下标”不能在类型一起使用“PFObject” 2)输入“CLLocation”错误没有下标构件 3 )型CLLocation的值没有任何成员“saveInBackgroundWithBlock”
RE编辑:我曾尝试这样做,得到一个警告,说“返回后的代码不会被执行”也其上运行的应用程序,但不保存
let geoPoint = PFObject(className: "location")
geoPoint["location"] = activePlace
geoPoint.saveInBackgroundWithBlock { (succes, error) -> Void in
print("place has been saved")
}
你还没有解释你的代码在做什么错误 – Wain
它没有做错任何事情,但它没有上传到解析。我只是不知道如何添加我必须解析的位置@Wain –
您是否定义了一个PFObject来保存您的位置/每个位置? – Wain