我对iOS编程很新,我自学了如何使用Swift。我需要为我正在为课程制作的应用设置地理围栏。我的问题是在初始化CLCircularRegion时出现错误,上面写着“使用未声明的类型'中心'”。我按照Apple开发者网站上的文件,不知道我做错了什么。任何帮助将不胜感激。谢谢。
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.
}
}
答案 0 :(得分:1)
广泛地......代码似乎没问题
1)尝试在类型注释之前留空格,例如从var center:CLLocationCoordinate2D
到此var center: CLLocationCoordinate2D
和
2)尝试清理DerivedData,重新启动Xcode ..