title: How to access Google Maps marker data stored in marker.userData in Swift
body: <p>I am currently trying to dynamically display data in a Google Maps markerInfoWindow about it's specific location using the marker.userData property.</p>
  
  <p>This is my function that sets marker.userData and puts markers on my map instance:</p>
  
  <pre><code>func putPlaces(places: [Place]) {
          for place in places.prefix(10) {
              print("*******NEW PLACE********")
              let name = place.name
              let address = place.address
              let location = ("lat: \(place.geometry.location.latitude), lng: \(place.geometry.location.longitude)")
              let locLat = place.geometry.location.latitude
              let locLon = place.geometry.location.longitude
              let place_id = place.place_id
              let photo = place.photos
              let types = place.types
  
              let marker : GMSMarker = GMSMarker()
              marker.position = CLLocationCoordinate2D(latitude: locLat, longitude: locLon)
              marker.icon = GMSMarker.markerImage(with: .black)
  
              print("PLACE: \(place)")
              print("PLACE.NAME: \(place.name)")
              marker.userData = ["name" : "names"]
              marker.map = self.mapView
           }
       }
  </code></pre>
  
  <p>I can see the specific place.name printed here^^^</p>
  
  <p>This is my function (copied from GoogleMapsAPI documentation) where I am trying to access elements of the data in marker.userData:</p>
  
  <pre><code>    func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -&gt; UIView? {
          print("Showing marker infowindow")
          print("marker.userData: \(marker.userData)")
  //      error here!vvv
  //      print("marker.userData.name: \(marker.userData.name)")
  //      here I will pass this data to a swiftUI view that will display the data within marker.userData
          let mInfoWindow = UIHostingController(rootView: MarkerInfoWindow())
          mInfoWindow.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width - 48, height: 80)
          return mInfoWindow.view
      }
  </code></pre>
  
  <p>This is the data im storing in marker.userData (taken from console when marker.userData is printed):</p>
  
  <pre><code>Optional(GMapProj.Place(geometry: GMapProj.Place.Location(location: GMapProj.Place.Location.LatLong(latitude: 42.3405476, longitude: -71.1465262)), name: "Boston Management Office", place_id: "ChIJpYqcF01444kRO8JeAqK2NuE", openingHours: Optional(GMapProj.Place.OpenNow(isOpen: false)), photos: nil, types: ["real_estate_agency", "point_of_interest", "establishment"], address: "113 Kilsyth Road # B, Brighton"))
  </code></pre>
  
  <p>In the last function above I try to print out the 'name' element within marker.userData, but I keep getting an error saying 'Value of type 'Any?' has no member 'name'. But i can access the name when printing right before i put the data in marker.userData...</p>
  
  <p>Anyone know how I can access the data stored in marker.userData and read it's elements??</p>