我正在尝试将cllocationcoordinate2d转换为cllocation。我在下面的代码的第12行收到错误“容器文字中的预期表达式”。我也在第13行得到错误“无法将cllocationcoordinate2d类型的值转换为期望值cllocation”,但这是因为第12行无法正常工作。
@IBAction func makeEvent(sender: UIButton)
{
let center = CLLocationCoordinate2D(latitude: loc1.coordinate.latitude, longitude: loc1.coordinate.longitude)
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
self.pointAnnotation1 = MKPointAnnotation()
self.pointAnnotation1.title = "Event"
self.pointAnnotation1.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long)
self.pinAnnotationView = MKPinAnnotationView(annotation: self.pointAnnotation1, reuseIdentifier: nil)
self.mapView?.centerCoordinate = self.pointAnnotation1.coordinate
self.mapView.addAnnotation(self.pinAnnotationView.annotation!)
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
eventRecord.setObject(center, forKey: "event")
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(eventRecord) { record, error in
}
if error == nil
{
print("Location saved")
}
loadEvent(){ (error, records) in
if error != nil {
print("error fetching locations")
} else {
print("Found Event")
}
}
}
答案 0 :(得分:3)
你正在混淆客观c和swift。 试试这个:
let center = CLLocation(latitude: lat, longitude: long)
而不是:
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]