[英]Error converting CLLocationCoordinate2D to CLLocation in Swift
I am trying to convert a cllocationcoordinate2d into a cllocation.我正在尝试将 cllocationcoordinate2d 转换为 cllocation。 I get the error "Expected expression in container literal" on line 12 of the code below.
我在下面代码的第 12 行收到错误“容器文字中的预期表达式”。 I also get the error "Cannot convert value of type cllocationcoordinate2d into expected value cllocation" on line 13 but that is because line 12 isn't working correctly.
我还在第 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")
}
}
}
You are mixing up Objective-C and Swift.您正在混淆 Objective-C 和 Swift。
Try this:尝试这个:
let center = CLLocation(latitude: lat, longitude: long)
Instead of:代替:
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.