所以我是应用程序开发的新手,我试图了解用户LocationManager的工作原理。我此时的目标是“请求授权”#34; >检查它是否已获得授权" > if true {获取变量中的位置和商店坐标}
这是我的代码:
let locationManager = CLLocationManager()
var coordinates: String?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
aivRefresh.hidden = true
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){
if locations != nil {
var location:CLLocationCoordinate2D = manager.location.coordinate
coordinates = "\(location.longitude),\(location.latitude)"
}