我正在尝试查找当前位置坐标,但我的程序没有调用didUpdateLocations
方法。我还在NSLocationWhenInUseUsageDescription
中添加了info.plist
。请帮忙(我使用的是7.2(7C68)版)。我只测试模拟器。
import UIKit
import CoreLocation
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var location: CLLocationManager!
override func viewDidLoad() {
let location = CLLocationManager()
location.delegate = self
location.desiredAccuracy = kCLLocationAccuracyBest
location.startUpdatingLocation()
location.requestWhenInUseAuthorization()
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let cord = locations[0] as CLLocation
let lati = cord.coordinate.latitude
let long = cord.coordinate.longitude
print(lati,"",long)
}
}