我正在尝试实施GoogleMaps,但我甚至无法让CLLocationManager工作。 didUpdateLocations
方法未运行。这是我的控制者:
import UIKit
import CoreLocation
import GoogleMaps
...
class RootMapViewController: UIViewController {
let locationManager = CLLocationManager()
@IBOutlet weak var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
fetchLocation()
...
}
func addMapPin(coordinates: CLLocationCoordinate2D, title: String, description: String) {
...
}
private func fetchLocation() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
}
private func centerMapOn(userCoordinates: CLLocationCoordinate2D) {
...
}
}
// MARK: CLLocationManagerDelegate
extension RootMapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
print("gggggggggggggggggg") // <----------------- prints properly ****
locationManager.startUpdatingLocation()
print("hhhhh")
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
}
// ISSUE ARISES HERE: *****************************************
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("zzzzzzzzzzzzzzzzzzz") // <----------------- doesn't print ****
let userCoordinates = manager.location!.coordinate
centerMapOn(userCoordinates)
locationManager.stopUpdatingLocation()
}
}
我的Info.plist文件有密钥:
更新
答案 0 :(得分:0)
你必须致电
locationManager.startUpdatingLocation;
在fetchLocation()函数的最后一行。