0

I've got this code:

override func viewDidLoad() {
    super.viewDidLoad()

    locationManager.delegate = self
    locationManager.requestWhenInUseAuthorization()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()

}

and this code:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userLocation = locations.last
    print(userLocation)
    let camera = GMSCameraPosition.cameraWithLatitude(userLocation!.coordinate.latitude,
                                                      longitude: userLocation!.coordinate.longitude, zoom: 12.5)

    self.mapView.camera = camera
    self.mapView.myLocationEnabled = true
    // self.mapView.settings.myLocationButton = true

    locationManager.stopUpdatingLocation()
}

This was working earlier but now it seems like locationManager isn't even being called as the print statement isn't returning any information at all. There are no errors in the code and I can't seem to figure out why the function isn't being called. Can anyone spot anything obvious that I'm missing?

Thank you

tryingtolearn
  • 2,528
  • 7
  • 26
  • 45
  • Check this [SO question](http://stackoverflow.com/questions/26192480/cannot-get-my-location-to-show-up-in-google-maps-in-ios-8?rq=), if it can help you. – KENdi Jul 28 '16 at 15:04
  • @KENdi unfortunately it isn't the same issue I think. For some reason the function just isn't being called. Any idea? – tryingtolearn Jul 29 '16 at 13:37

1 Answers1

0

I just implemented this and I'm going to say you what I've done

First, you create a locationManager variable

let locationManager: CLLocationManager = CLLocationManager()

You have to request permission in the viewDidLoad()

viewMap.delegate = self
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()

Then, I created an extension and I implemented the delegate

extension MyView: CLLocationManagerDelegate {

  func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
   //here you configure the locationManager

  locationManager.startUpdatingLocation()

    viewMap.isMyLocationEnabled = true
    viewMap.settings.myLocationButton = true
}

  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    }

}

I hope this help you, here works properly.

Gulfam Khan
  • 1,010
  • 12
  • 23
David Luque
  • 1,078
  • 5
  • 18
  • 30