在 Swift 中初始化 CLCircularRegion



我对 iOS 编程相当陌生,正在自学如何使用 Swift。我需要为我为课程制作的应用程序设置地理围栏。我的问题是在初始化CLCircularRegion时,我收到一个错误,说"使用未声明的类型'中心'"。我关注了苹果开发者网站上的文件,不知道我做错了什么。任何帮助将不胜感激。谢谢。

import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var mapView: MKMapView!
var manager = CLLocationManager()
@IBAction func startMonitoring(sender: AnyObject) {
    // 43.039278, -87.932479 mccormick hall location
    var latitude:CLLocationDegrees = 43.039278
    var longitude:CLLocationDegrees = -87.932479
    var center:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var radius:CLLocationDistance = CLLocationDistance(10.0)
    var identifier:String = "vicmic"
    var geoRegion:CLCircularRegion = CLCircularRegion(center: center, radius: radius, identifier: identifier)
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Core Location
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

广义....代码似乎还可以

1)尝试在类型注释之前留空格,例如从var center:CLLocationCoordinate2D到此var center: CLLocationCoordinate2D

2)尝试清理你的衍生数据,重新启动Xcode。

相关内容

  • 没有找到相关文章

最新更新