如何在不同的郊区覆盖带有彩色的 ta GMSMapView?

How do I overlay a ta GMSMapView with tinted colors over different suburbs?

我正在使用 Swift 构建应用程序。我已经使用以下代码成功地将 google 地图添加到我的应用程序作为我的主视图控制器上的子视图:

let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
var mapView = GMSMapView.map(withFrame: CGRect(x: screenWidth*0.03, y: 245, width: screenWidth*0.94, height: screenHeight*0.45), camera: camera)
self.view.addSubview(mapView)

我现在想做一些听起来有点棘手的事情,但我确信这是可能的。我希望能够覆盖我的 mapView 中地图的不同区域,这些区域由名称或邮政编码指定,具有不同的可点击颜色。这似乎是使地图变得漂亮的常用方法,而且我相信有一个现有的解决方案可以轻松做到这一点。我应该怎么做?

我找到方法了! Google地图API提供!一旦你像我原来的问题一样设置了你的地图,你可以这样做来向地图添加一个圆圈:

let circleCenter = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
let circ = GMSCircle(position: circleCenter, radius: 2000)
circ.fillColor = UIColor.green.withAlphaComponent(0.5)
circ.map = mapView

您还可以绘制包含一系列 lat/longs 的更复杂的形状,如下所示:

let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.886080, longitude: -122.137585))
rect.add(CLLocationCoordinate2D(latitude: 37.899356, longitude: -122.130203))
rect.add(CLLocationCoordinate2D(latitude: 37.900101, longitude: -122.104282))
rect.add(CLLocationCoordinate2D(latitude: 37.879644, longitude: -122.101192))
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor.flatWatermelonDark.withAlphaComponent(0.5)
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.isTappable = true
polygon.map = mapView

我还没有想出一种无缝的方式来覆盖任何邮政编码,但这可以通过查看 up/estimating 邮政编码区域的 lat/long 边缘,使用上述代码片段手动完成.