title: Google maps overlay multiple polygons in swift
body: <p>There is a great answer on <a href="https://stackoverflow.com/questions/23154254/google-map-multiple-overlay-no-cumulative-opacity">SO</a> on merging polygons in Google maps for javascript. Now I took this and converted it over to swift. This is primarily working but am encountering blanks in some of the circles so I'm not sure if the conversion is completely correct or not.</p>
  
  <p><a href="https://i.stack.imgur.com/cdFyb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cdFyb.jpg" alt="enter image description here"></a></p>
  
  <p>The swift code of the converted JS looks like so</p>
  
  <pre><code>func setFloodPolygons(mData: Floods) {    
      let rect = GMSMutablePath()
      var circCoordinates: [CLLocationCoordinate2D] = []
      for flood in mData.Floods {
          circCoordinates.append(contentsOf: drawPolygonCircle(coord: CLLocationCoordinate2D.init(latitude: flood.lat, longitude: flood.lng), radius: 3.0, dir: 1))
      }
  
      for coo in circCoordinates {
          rect.add(coo)
      }
  
      // Create the polygon, and assign it to the map.
      let polygon = GMSPolygon(path: rect)
      polygon.fillColor = UIColor(red: 144/255, green: 195/255, blue: 212/255, alpha: 0.75)
      polygon.strokeColor = UIColor(red: 144/255, green: 195/255, blue: 212/255, alpha: 0.75)
      polygon.strokeWidth = 1
      polygon.zIndex = 1
      polygon.map = mapView
  }
  </code></pre>
  
  <p>and the circle function is</p>
  
  <pre><code>func drawPolygonCircle(coord: CLLocationCoordinate2D, radius: Double, dir: Int) -&gt; [CLLocationCoordinate2D]{
      let d2r = Double.pi / 180   // degrees to radians
      let r2d = 180 / Double.pi   // radians to degrees
      let earthsradius = 3963.0 // 3963 is the radius of the earth in miles
      let points = 32
      let rlat = (radius / earthsradius) * r2d
      let rlng = rlat / cos(coord.latitude * d2r)
  
      var extp: [CLLocationCoordinate2D] = []
      let start = 0
      let end = points
  
      for i in start...end {
          let j = i + dir
          let theta = Double.pi * (Double(j) / Double(points / 2));
          let ey = coord.longitude + (rlng * cos(theta)); // center a + radius x * cos(theta)
          let ex = coord.latitude + (rlat * sin(theta)); // center b + radius y * sin(theta)
          extp.append(CLLocationCoordinate2D.init(latitude: ex, longitude: ey))
      }
      return extp;
  }
  </code></pre>
  
  <p>When the same thing is done using the identical coordinates in a web page, the circles show correctly. </p>
  
  <p>The gaps I've determined is what the polygon would look like not going through the circle function. </p>
  
  <p>Can anyone see what may need adjustment to get the gaps filled or have an idea of what I did wrong in the conversion?</p>
  
  <p>UPDATE:</p>
  
  <p>This is an acknowledged bug by Google. You can look at the bug report over at <a href="https://issuetracker.google.com/issues/79475939" rel="nofollow noreferrer">https://issuetracker.google.com/issues/79475939</a>. Maybe add a comment to encourage Google to look at it sooner.</p>