ios - 在 Swift 中将 CLLocationCoordinate2D 转换为 CLLocation 时出错

标签 ios swift xcode cllocationmanager cloudkit

我正在尝试将 clocationcoordinate2d 转换为 clocation。我在下面代码的第 12 行收到错误“容器文字中的预期表达式”。我还在第 13 行收到错误“无法将类型 clocationcoordinate2d 的值转换为预期值 clocation”,但这是因为第 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")
            }
        }
    }

最佳答案

你混淆了 Objective-C 和 Swift。

试试这个:

let center = CLLocation(latitude: lat, longitude: long)

代替:

CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]

关于ios - 在 Swift 中将 CLLocationCoordinate2D 转换为 CLLocation 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39257874/

相关文章:

xcode - 按下注销按钮时访问登录 View Controller

ios - 使用代码启动 View Controller 时标题和导航栏消失

iOS 9 检测静音模式

ios - 点击 UISearchController(搜索栏)时显示日期选择器

swift - 查看pdf文档

ios - UIView.animateWithDuration 快速循环动画

ios - iOS8 beta 5 上的 UIWebView 中的定位服务无法正常工作

ios - 检测子层元素上的触摸

ios - 以编程方式从 collectionView Cell didSelectItemAt 推送到新的 ViewController - swift

ios - 如何快速创建可扩展的文本字段/标签?