gpt4 book ai didi

swift - 如何将位置(引脚)保存到解析服务器?

转载 作者:行者123 更新时间:2023-11-30 10:05:31 25 4
gpt4 key购买 nike

我有一个应用程序,可以在表格 View 中显示位置,可以通过 map 上的按钮添加位置。我在保存这些解析时遇到了麻烦(是的,我知道它正在退役,但我已经设置了一个工作原理完全相同的新服务器,所以认为它是解析的)还要注意我已经看过这个主题:https://stackoverflow.com/questions/30435362/how-can-i-send-coordinates-to-parse-and-save-it-as-parse-pfgeopoin即使它看起来很简单,它仍然让我感到困惑,所以这是我的表格 View 中的代码

var places = [Dictionary<String,String>()]

var activePlace = -1

这是广告图钉的代码(在 map View Controller 中)

 @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”

重新编辑:我已经尝试过此操作并收到警告,提示“返回后的代码将永远不会被执行”,并且它在应用程序上运行但不保存

    let geoPoint = PFObject(className: "location")

geoPoint["location"] = activePlace
geoPoint.saveInBackgroundWithBlock { (succes, error) -> Void in
print("place has been saved")
}

最佳答案

因此,您需要一些东西来包含您的 PFGeoPoint,并且该东西必须是 PFObject。在解析后端,您可以为此对象创建表,并使用对 geoPoint 的引用以及您想要的任何其他内容来设置它。现在,您可以使用表的类名为每个新点实例化一个 PFObject,设置对 geoPoint 的引用(使用 pfObject["geoPoint"] = geoPoint),保存它(使用 pfObject.saveInBackgroundWithBlock...),就完成了。

关于swift - 如何将位置(引脚)保存到解析服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36281393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com