我对 iOS 编程相当陌生,并且正在自学如何使用 Swift。我需要为我为班级制作的应用程序设置地理围栏。我的问题是在初始化 CLCircularRegion 时,我收到一条错误消息,上面写着“使用未声明的类型 'center' ”。我遵循了 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.
}
}