title: How to put Google Maps in TableView - Swift 3
body: <p>I'm new to Swift Programming. I'm trying to put Google Map in <code>UITableView</code>. Can I do that?</p>
  
  <p>The User Interface should be like this:</p>
  
  <p><a href="https://i.stack.imgur.com/hGp1D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hGp1D.png" alt="enter image description here"></a></p>
  
  <p>Here is my code for implementing UITableView using Storyboard:</p>
  
  <pre><code>    override func numberOfSections(in tableView: UITableView) -&gt; Int {
  
          return 3
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          var rowCount = 0
  
          if section == 0 {
              rowCount = 1
          }
  
          if section == 1 {
              rowCount = arrayOfStatic.count
          }
          if section == 2 {
              rowCount = arrayOfDynamic.count
          }
  
          return rowCount
      }
  
      override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
  
          if indexPath.section == 0 {
              return 250
          } else {
              return 70
          }
      }
  
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      if indexPath.section == 0 {
          let cell = tableView.dequeueReusableCell(withIdentifier: "mapsCellId", for: indexPath) as! GoogleMapsCell
          return cell
      } else if indexPath.section == 1 {
          let cell = tableView.dequeueReusableCell(withIdentifier: "staticCellId", for: indexPath) as! StaticCell
          return cell
      } else {
          let cell = tableView.dequeueReusableCell(withIdentifier: "placesCellId", for: indexPath) as! PlacesCell
          let ip = indexPath
  
          cell.imageFoursquarePlaces.image = arrayOfDynamic[indexPath.row].image
          cell.labelPlacesName.text = arrayOfDynamic[ip.row].name
          cell.labelPlacesCategory.text = arrayOfDynamic[ip.row].category
          return cell
      }
  }
  </code></pre>
  
  <p>Here is my code for implementing <code>UITableViewCell</code> in the first section of <code>UITableView</code>:</p>
  
  <pre><code>class GoogleMapsCell: UITableViewCell, GMSMapViewDelegate, CLLocationManagerDelegate {
      @IBOutlet weak var googleMapsView: UIView!
      @IBOutlet weak var buttonCurrentLoc: UIButton!
  
      var googleMaps: GMSMapView!
      var locationManager = CLLocationManager()
      var camera = GMSCameraPosition()
  
      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
          self.showCurrentLocationOnMap()
          self.locationManager.stopUpdatingLocation()
      }
  
      func showCurrentLocationOnMap() {
  
          self.locationManager.delegate = self
          self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
          self.locationManager.requestWhenInUseAuthorization()
          self.locationManager.startUpdatingLocation()
  
          let camera = GMSCameraPosition.camera(withLatitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location?.coordinate.longitude)!, zoom: 15)
          self.googleMaps = GMSMapView.map(withFrame: CGRect(x: 0,y: 0, width: self.googleMapsView.frame.size.width, height: self.googleMapsView.frame.height), camera: camera)
  
          do {
              if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") {
                  self.googleMaps.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
              } else {
                  NSLog("Unable to find style.json")
              }
          } catch {
              NSLog("The style definition could not be loaded: \(error)")
          }
          self.googleMaps.isMyLocationEnabled = true
          self.googleMaps.accessibilityElementsHidden = false
  
          self.addSubview(self.googleMaps)
          self.googleMaps.camera = camera
          self.addSubview(self.buttonCurrentLoc)
      }
  
  }
  </code></pre>
  
  <p>It gives me result:</p>
  
  <p><a href="https://i.stack.imgur.com/hr70N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hr70N.png" alt="enter image description here"></a></p>
  
  <p>I have a <code>searchBar</code> as <code>HeaderView</code>. I tried to put Google Map View by creating a <code>UIView</code> inside the first cell of TableView. But I can't show the Google Map View and the button can't be clicked. How can I do that?</p>
  
  <p>Any help would be appreciated :)</p>