title: Getting location in swift 5
body: <p>I realize there are lots of other pages that attempt to solve the challenge of getting user location using <code>CLLocationManager()</code> in ios swift but they don't work for me which is why I created this question. My code is below which I believe correctly implements the <code>CLLocationManagerDelegate</code> but the call to <code>locationManager.startUpdatingLocation()</code> never calls the <code>locationManager</code> function. This makes the Google Map simply open to a random position. I've simulated certain locations in the scheme and they work great like South Africa </p>
  
  <p>example of Google Map with simulated location: 
  <a href="https://i.stack.imgur.com/ZEItH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZEItH.png" alt=""></a></p>
  
  <p>However, when I uncheck the simulation, the location is never found. Any advice or help would be appreciated. Not sure if this is a problem with my computer or code.</p>
  
  <pre><code>import UIKit
  import GoogleMaps
  
  class Map: UIViewController, CLLocationManagerDelegate  {
  
      var mapView: GMSMapView?
      let locationManager = CLLocationManager()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: GMSCameraPosition.camera(withLatitude: 40.7, longitude: -74.0, zoom: 4.0))
          view = mapView
  
          if (CLLocationManager.locationServicesEnabled()){
              locationManager.delegate = self
              locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
              locationManager.requestWhenInUseAuthorization()
              locationManager.startUpdatingLocation()
          }
  
      }
  
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  
          let center = CLLocationCoordinate2D(latitude: locations.last!.coordinate.latitude, longitude: locations.last!.coordinate.longitude)
  
          let camera = GMSCameraPosition.camera(withLatitude: center.latitude, longitude: center.longitude, zoom: 4.0);
          self.mapView?.camera = camera
          self.mapView?.isMyLocationEnabled = true
  
          let marker = GMSMarker(position: center)
  
          print("Latitude :\(center.latitude)")
          print("Longitude :\(center.longitude)")
  
          marker.map = self.mapView
          marker.title = "Current Location"
  
          locationManager.stopUpdatingLocation()
      }
  
  }
  </code></pre>