我的代码存在问题,didUpdateLocations
函数从未被调用过。
我还添加了两个键NSLocationWhenInUseUsageDescription
和NSLocationAlwaysUsageDescription
。我不知道如果有人可以提供帮助,会发生什么事
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
if status == .AuthorizedWhenInUse
{
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
}
func locationManager (manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
if let location = locations.first
{
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
print(locationManager.location?.coordinate)
}
}