title: How to focus on user location using SwiftUI and GoogleMaps iOS SDK
body: <p>Im still new to Xcode and SwiftUI so my apologies if this is simple to some people. Essentially, Im making an app that uses GoogleMaps iOS SDK and I'm trying to figure out how to focus the map's camera to a user's current location at startup.</p>
  
  <p>Right now the way my code works is I have a main view which calls the GoogleMaps view and a couple of other views. The map initializes and the map's camera focuses on a set location i defined (Boston), drops a pin in a specific location (Boston), it displays my current location with a blue dot, and the camera focuses on my current location ONLY AFTER the myLocation button is tapped (which is inherent to Google Maps).</p>
  
  <p>My main view that calls my Google maps view is here:</p>
  
  <pre><code>
  import SwiftUI
  
  struct LandmarkList: View {
  
      @State private var searchText = ""
      @State private var locationText = ""
  
      var body: some View {
  
          NavigationView {
  
              GoogMapView()
                  .frame(height: 750)
          }
          .edgesIgnoringSafeArea(.vertical)
          .navigationBarItems(leading:
  
          TextField("Current Location",text: self.$locationText)
          .textFieldStyle(RoundedBorderTextFieldStyle())
          .multilineTextAlignment(.leading)
          .frame(width: 375)
              )
  
          }
  </code></pre>
  
  <p>My Google maps view (i call it GoogMapView):
  UPDATED BASED ON COMMENTS &amp; TUTORIAL BELOW:</p>
  
  <pre><code>import SwiftUI
  //import MapKit
  import UIKit
  import GoogleMaps
  import GooglePlaces
  
  
  private let locationManager = CLLocationManager()
  
  struct GoogMapView : UIViewRepresentable {
  
          let marker : GMSMarker = GMSMarker()
  
          //Creates a `UIView` instance to be presented.
          func makeUIView(context: Self.Context) -&gt; GMSMapView {
              // Create a GMSCameraPosition
              let camera = GMSCameraPosition.camera(withLatitude: 42.361145, longitude: -71.057083, zoom: 16.0)
              let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
              mapView.setMinZoom(14, maxZoom: 20)
              mapView.settings.compassButton = true
              mapView.isMyLocationEnabled = true
              mapView.settings.myLocationButton = true
              mapView.settings.scrollGestures = true
              mapView.settings.zoomGestures = true
              mapView.settings.rotateGestures = true
              mapView.settings.tiltGestures = true
              mapView.isIndoorEnabled = false
  
              if let mylocation = mapView.myLocation {
                print("User's location: \(mylocation)")
              } else {
                print("User's location is unknown")
              }
              locationManager.delegate = self
              locationManager.requestWhenInUseAuthorization()
  
              return mapView
          }
  
  //        Updates the presented `UIView` (and coordinator) to the latestconfiguration.
          func updateUIView(_ mapView: GMSMapView, context: Self.Context) {
              // Creates a marker in the center of the map.
              marker.position = CLLocationCoordinate2D(latitude: 42.361145, longitude: -71.057083)
              marker.title = "Boston"
              marker.snippet = "USA"
              marker.map = mapView
          }
  }
  </code></pre>
  
  <p>I thought i could grab mapView.myLocation and use that to manually focus the map camera on startup but that didnt work. You can see in the code above i try to print out the location but all i get back is 'User's location is unknown'.
  Also, now getting an error 'Cannot assign value of type 'GoogMapView' to type 'CLLocationManagerDelegate?'' where i type 'locationManager.delegate = self'.</p>
  
  <p>Does anyone have an idea of the 'proper' way to have the map camera focus on a user's current location at startup?</p>