形狀

選取平台: Android iOS JavaScript

Maps SDK for iOS 提供了一些在地圖中加入形狀的簡單做法。下面的圖形支持:

  • 折線是連續線段,可構成您想要的任何形狀,並可用來標記地圖上的路徑和路線。
  • 多邊形是一個封閉的形狀,可用於在地圖上標記的區域。
  • 圓形是地球表面的圓形精確投影。

你可以修改每個形狀的多種方式的外觀。

折線

折線讓你在地圖上繪製線條。GMSPolyline 物件代表地點的序列順序,以一系列線段顯示。您可以使用 GMSStrokeStyle 設定折線顏色。

如要建立折線,您必須建立含有兩個或以上點的對應 GMSMutablePath 物件,藉此指定折線路徑。每個 CLLocationCoordinate2D 都代表地球表面上的一個點。根據您在路徑中新增路徑的順序,系統會在點與點之間繪製線段。您可以用 addCoordinate:addLatitude:longitude: 方法在路徑中新增路徑。

Swift

let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: -33.85, longitude: 151.20))
path.add(CLLocationCoordinate2D(latitude: -33.70, longitude: 151.40))
path.add(CLLocationCoordinate2D(latitude: -33.73, longitude: 151.41))
let polyline = GMSPolyline(path: path)
      

Objective-C

GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(-33.85, 151.20)];
[path addCoordinate:CLLocationCoordinate2DMake(-33.70, 151.40)];
[path addCoordinate:CLLocationCoordinate2DMake(-33.73, 151.41)];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
      

加入折線

  1. 建立 GMSMutablePath 物件。
  2. 使用 addCoordinate:addLatitude:longitude: 方法在路徑中設定點。
  3. 使用路徑做為引數,將新的 GMSPolyline 物件執行個體化。
  4. 視需要設定其他屬性,例如 strokeWidthstrokeColor
  5. 設定 GMSPolylinemap 屬性。
  6. 折線將出現在地圖上。

下面的代碼片斷添加一個矩形的地圖:

Swift

let rectanglePath = GMSMutablePath()
rectanglePath.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rectanglePath.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rectanglePath.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rectanglePath.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
rectanglePath.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))

let rectangle = GMSPolyline(path: path)
rectangle.map = mapView
      

Objective-C

GMSMutablePath *rectanglePath = [GMSMutablePath path];
[rectanglePath addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[rectanglePath addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[rectanglePath addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[rectanglePath addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];
[rectanglePath addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];

GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
rectangle.map = mapView;
      

矩形多段線

移除折線

您可以將 GMSPolylinemap 屬性設為 nil,從地圖中移除折線。或者,您也可以呼叫 GMSMapView clear 方法,移除目前地圖上所有疊加層 (包括折線和其他形狀)。

Swift

mapView.clear()
      

Objective-C

[mapView clear];
      

自訂折線

GMSPolyline 物件提供多個屬性,可用於控制線條的外觀。它支持下面的選項:

strokeWidth
整個行的寬度,在螢幕點中。默認為1。縮放地圖時,寬度的尺寸不會改變。
geodesic
YES 時,將此折線邊緣顯示為測地線。測地線段跟隨地球表面的最短路徑,並透過麥卡托投影地圖在地圖上呈現為曲線。非測地線段在地圖上繪製成直線。這個變數預設為 NO
spans
用於指定折線的一或多個區隔顏色。Span 屬性是 GMSStyleSpan 物件的陣列。如要設定折線的顏色,建議設定 spans 屬性。
strokeColor
UIColor 物件,指定折線的顏色。預設為 blueColor。如果設定 spans,則系統會忽略 strokeColor 屬性。

下列程式碼片段會針對墨爾本至伯斯的粗細折線,和測地線插入。

Swift

let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 10.0
polyline.geodesic = true
polyline.map = mapView
      

Objective-C

GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 10.f;
polyline.geodesic = YES;
polyline.map = mapView;
      

如果您在將折線加入地圖後修改折線,請務必保留 GMSPolyline 物件。

Swift

polyline.strokeColor = .blue
      

Objective-C

polyline.strokeColor = [UIColor blueColor];
      

變更折線的顏色

折線是由地圖上一系列所組成的折線。您可以透過 spans 屬性變更個別或整個線條的顏色。雖然這個屬性可讓您控制折線的色彩,但為了方便起見,您可以輕鬆將折線套用至整個線條。

下列程式碼片段使用 spanWithColor: 方法,將整行顏色變更為紅色。

Swift

polyline.spans = [GMSStyleSpan(color: .red)]
      

Objective-C

polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor redColor]]];
      

或者,如果您已取得 GMSStrokeStyle 物件的存取權,也可以使用 spanWithStyle: 方法。

Swift

let solidRed = GMSStrokeStyle.solidColor(.red)
polyline.spans = [GMSStyleSpan(style: solidRed)]
      

Objective-C

GMSStrokeStyle *solidRed = [GMSStrokeStyle solidColor:[UIColor redColor]];
polyline.spans = @[[GMSStyleSpan spanWithStyle:solidRed]];
      

在 Maps SDK for iOS 1.7 以下版本中,您可以使用 strokeColor 單一屬性來設定 GMSPolyline 的完整顏色。spans 屬性的優先順序高於 strokeColor

Swift

polyline.strokeColor = .red
      

Objective-C

polyline.strokeColor = [UIColor redColor];
      

樣式

如果應用程式多次套用相同的筆劃顏色,您可能會覺得定義可重複使用的樣式會很有幫助。系統會使用 GMSStrokeStyle 物件指定折線樣式。筆劃樣式可以是純色,或從一種顏色到另一個顏色的漸層。建立樣式後,您可以使用 spanWithStyle: 方法將樣式套用到 GMSStyleSpan

Swift

// Create two styles: one that is solid blue, and one that is a gradient from red to yellow
let solidBlue = GMSStrokeStyle.solidColor(.blue)
let solidBlueSpan = GMSStyleSpan(style: solidBlue)
let redYellow = GMSStrokeStyle.gradient(from: .red, to: .yellow)
let redYellowSpan = GMSStyleSpan(style: redYellow)
      

Objective-C

// Create two styles: one that is solid blue, and one that is a gradient from red to yellow
GMSStrokeStyle *solidBlue = [GMSStrokeStyle solidColor:[UIColor blueColor]];
GMSStyleSpan *solidBlueSpan = [GMSStyleSpan spanWithStyle:solidBlue];
GMSStrokeStyle *redYellow =
    [GMSStrokeStyle gradientFromColor:[UIColor redColor] toColor:[UIColor yellowColor]];
GMSStyleSpan *redYellowSpan = [GMSStyleSpan spanWithStyle:redYellow];
      

span 的樣式會繼續使用,直到折線結束,或直到設定新樣式為止。如要變更折線的色彩,您可以將折線的 spans 屬性設為單一 GMSStyleSpan 示範如何使用折線套用整個折線的漸層。

Swift

polyline.spans = [GMSStyleSpan(style: redYellow)]
      

Objective-C

polyline.spans = @[[GMSStyleSpan spanWithStyle:redYellow]];
      

變更個別線段的顏色

如要個別設定折線的個別樣式,您可以建立 GMSStyleSpan 物件陣列並傳送至 spans 屬性。根據預設,陣列的各個項目會設定對應線段的顏色。如果陣列中的元素更多於行中的區隔,系統會忽略額外元素。如果陣列中的元素較少,則最後一個 GMSStyleSpan 會描述線條的剩餘顏色。

您可以使用顏色區塊和/或漸層折線,表示折線上的變化 (例如高度或速度)。下列程式碼片段會將折線前兩個部分的顏色設為紅色,線條的其餘部分則是從紅色到黃色的漸層。

Swift

polyline.spans = [
  GMSStyleSpan(style: solidRed),
  GMSStyleSpan(style: solidRed),
  GMSStyleSpan(style: redYellow)
]
      

Objective-C

polyline.spans = @[[GMSStyleSpan spanWithStyle:solidRed],
                   [GMSStyleSpan spanWithStyle:solidRed],
                   [GMSStyleSpan spanWithStyle:redYellow]];
      

您可以使用 spanWithStyle:segments: 方法,一次設定多個區隔的樣式。舉例來說,以下程式碼相當於上述程式碼。系統會一律忽略最終 GMSStyleSpan 的區隔長度,因為樣式會用於描述線條的其餘部分。

Swift

polyline.spans = [
  GMSStyleSpan(style: solidRed, segments:2),
  GMSStyleSpan(style: redYellow, segments:10)
]
      

Objective-C

polyline.spans = @[[GMSStyleSpan spanWithStyle:solidRed segments:2],
                   [GMSStyleSpan spanWithStyle:redYellow segments:10]];
      

小數區隔

區隔也可以指定為分數。此操作會將樣式套用至小部分的片段,並可能使某個片段分割成單一部分。每個 GMSStyleSpan 都可以在上一個片段之後開始執行:在以下範例中,灰色顏色會從第 2 個區隔開始,從第 1 個開始,直到第三個區隔結束 1⁄2。

Swift

polyline.spans = [
  GMSStyleSpan(style: solidRed, segments: 2.5),
  GMSStyleSpan(color: .gray),
  GMSStyleSpan(color: .purple, segments: 0.75),
  GMSStyleSpan(style: redYellow)
]
      

Objective-C

polyline.spans = @[[GMSStyleSpan spanWithStyle:solidRed segments:2.5],
                   [GMSStyleSpan spanWithColor:[UIColor grayColor]],
                   [GMSStyleSpan spanWithColor:[UIColor purpleColor] segments:0.75],
                   [GMSStyleSpan spanWithStyle:redYellow]];
      

在折線中新增重複的顏色模式

如果您想在折線中加入圖案,可以使用 GMSGeometryUtils 中的 GMSStyleSpans 公用程式方法。GMSStyleSpans 方法接受兩個定義重複模式的陣列。一個陣列會設定要重複顯示的樣式,另一個則定義重複的週期。搭配使用時,您可以建立一個可套用至所有折線的模式,無論長度或可用的區段數量都一樣。

例如,以下程式碼片段定義使用黑色和白色並混合模式的折線。其長度是以公尺線 (在 Mercator 中為直線) 為單位,因為類型會指定為 kGMSLengthRhumb

Swift

let styles = [
  GMSStrokeStyle.solidColor(.white),
  GMSStrokeStyle.solidColor(.black)
]
let lengths: [NSNumber] = [100000, 50000]
polyline.spans = GMSStyleSpans(
  polyline.path!,
  styles,
  lengths,
  GMSLengthKind.rhumb
)
      

Objective-C

NSArray *styles = @[[GMSStrokeStyle solidColor:[UIColor whiteColor]],
                    [GMSStrokeStyle solidColor:[UIColor blackColor]]];
NSArray *lengths = @[@100000, @50000];
polyline.spans = GMSStyleSpans(polyline.path, styles, lengths, kGMSLengthRhumb);
      

活潑的折線

「延展型折線」可讓你使用自選的點陣圖圖片建立折線。形狀使用明確的背景筆劃,但線條等處不會截斷,因此可用於繪製步行路線等情況。

基本戳記折線

您可以透過 GMSSpriteStyle 使用這項功能,並透過 GMSStrokeStylestampStyle 屬性將其設為戳記。

Swift

let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 20

let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
let stampStyle = GMSSpriteStyle(image: image)

let transparentStampStroke = GMSStrokeStyle.transparentStroke(withStamp: stampStyle)
let span = GMSStyleSpan(style: transparentStampStroke)
polyline.spans = [span]
polyline.map = mapView

Objective-C

GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];
polyline.strokeWidth = 20;
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];

UIImage *image = [UIImage imageNamed:@"imageFromBundleOrAsset"];
GMSStrokeStyle *transparentStampStroke = [GMSStrokeStyle transparentStrokeWithStampStyle:[GMSSpriteStyle spriteStyleWithImage:image]];

GMSStyleSpan *span = [GMSStyleSpan spanWithStyle:transparentStampStroke];
polyline.spans = @[span];
polyline.map = _mapView;

紋理戳記折線

紋理戳記折線可讓您透過自選的紋理建立折線。形狀應採用清晰、純色或漸層背景筆劃。紋理會隨著縮放等級變更而調整大小。路徑結尾或路徑點結尾的圖片會在特定縮放等級顯示

紋理折線

您可以透過 GMSTextureStyle 使用這項功能,並透過 GMSStrokeStylestampStyle 屬性將其設為戳記。

Swift

let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 20
let redWithStamp = GMSStrokeStyle.solidColor(.red)

let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
redWithStamp.stampStyle = GMSTextureStyle(image: image)

let span = GMSStyleSpan(style: redWithStamp)
polyline.spans = [span]
polyline.map = mapView

Objective-C

GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 20;
GMSStrokeStyle *redWithStamp = [GMSStrokeStyle solidColor:[UIColor redColor]];

UIImage *image = [UIImage imageNamed:@"imageFromBundleOrAsset"]; // Image could be from anywhere
redWithStamp.stampStyle = [GMSTextureStyle textureStyleWithImage:image];

GMSStyleSpan *span = [GMSStyleSpan spanWithStyle:redWithStamp];
polyline.spans = @[span];
polyline.map = _mapView;

地圖功能

GMSMapView 上的 mapCapabilities 屬性可新增地圖專屬功能的程式輔助檢查。您可以先瞭解特定地圖 capabilities 是否可用,再呼叫特定 API。這項查詢會判斷地圖檢視是否支援 Sprite 戳記折線。

Swift

let path = GMSMutablePath()
path.addLatitude(-37.81319, longitude: 144.96298)
path.addLatitude(-31.95285, longitude: 115.85734)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 20

let image = UIImage(named: "imageFromBundleOrAsset")! // Image could be from anywhere
let spans: [GMSStyleSpan]

if (mapView.mapCapabilities.contains(.spritePolylines)) {
 let spriteStyle = GMSSpriteStyle(image: image)
 let stroke = GMSStrokeStyle.transparentStroke(withStamp: spriteStyle)
spans = [ GMSStyleSpan(style: stroke) ]
} else {
 let stroke = GMSStrokeStyle.solidColor(.clear)
 stroke.stampStyle = GMSTextureStyle(image: image)
 spans = [ GMSStyleSpan(style: stroke) ]
}

polyline.spans = spans
polyline.map = mapView

Objective-C

GMSMutablePath *path = [GMSMutablePath path];
[path addLatitude:-37.81319 longitude:144.96298];
[path addLatitude:-31.95285 longitude:115.85734];

UIImage *_Nonnull image = [UIImage imageNamed:@"imageFromBundleOrAsset"]; // Image could be from anywhere

NSArray <GMSStyleSpan*> * spans;

if (_mapView.mapCapabilities & GMSMapCapabilityFlagsSpritePolylines) {
 GMSSpriteStyle *spriteStyle = [GMSSpriteStyle spriteStyleWithImage:image];
 GMSStrokeStyle *stroke = [GMSStrokeStyle transparentStrokeWithStampStyle:spriteStyle];
 spans = @[ [GMSStyleSpan spanWithStyle:stroke] ];
} else {
 GMSStrokeStyle *stroke = [GMSStrokeStyle solidColor:UIColor.clearColor];
 stroke.stampStyle = [GMSTextureStyle textureStyleWithImage:image];
 spans = @[ [GMSStyleSpan spanWithStyle:stroke] ];
}

GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 20;
polyline.spans = spans;
polyline.map = _mapView;

此模式可讓您訂閱變更,並回應地圖檢視狀態的更新。你也可以在 GMSMapViewDelegate 上實作 didChangeMapCapabilities,取得可用功能的最新資訊。

多邊形

多邊形與折線類似,都是由一系列座標依序組成。不過,多邊形並不是開放的線段,而是用來定義封閉式迴圈內的可靠區域。多邊形是由 Maps SDK for iOS 在 GMSPolygon 類別中定義。

在地圖中新增 GMSPolygon 的做法與加入 GMSPolyline 的方式相同。首先,請建立對應的 GMSMutablePath 物件並新增路徑點,藉此指定路徑。這些點會構成多邊形的外框。每個 CLLocationCoordinate2D 都代表地球表面上的一個點。根據您在路徑中新增路徑的順序,系統會在點與點之間繪製線段。

加入多邊形

  1. 建立 GMSMutablePath 物件。
  2. 使用 addCoordinate:addLatitude:longitude: 方法在路徑中設定點。這些點會構成多邊形的外框。
  3. 使用路徑做為引數,將新的 GMSPolygon 物件執行個體化。
  4. 視需要設定其他屬性,例如 strokeWidthstrokeColorfillColor
  5. 設定 GMSPolygon.map 屬性,將多邊形指派給 GMSMapView 物件。
  6. 地圖上會顯示這個多邊形。

以下程式碼片段會將矩形加進地圖。

Swift

// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))

// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
      

Objective-C

// Create a rectangular path
GMSMutablePath *rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];

// Create the polygon, and assign it to the map.
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = mapView;
      

不管是在將多邊形加入地圖之前或之後,您都可以自訂多邊形的外觀。

移除多邊形

移除多邊形的 GMSPolygon.map 屬性至 nil,並從其父項卸離 layer,藉此移除多邊形。

Swift

 polygon.map = nil
 polygon.layer.removeFromSuperLayer()

Objective-C

 polygon.map = nil;
 [polygon.layer removeFromSuperlayer];
 

圓圈

除了一般的 GMSPolygon 類別之外,Maps SDK for iOS 還提供 GMSCircle,可讓您輕鬆在地表上繪製圓形。

如要建構圓形,您必須指定以下兩個屬性:

  • CLLocationCoordinate2D 格式指定的 position
  • radius (單位為公尺)。

接著,將圓形定義為地球表面上距離 center radius 公尺的所有點的集合。Maps API 使用的麥卡托投影會在平面上算繪球體,而受到該投影方式的影響,圓形位於赤道附近時,在地圖上呈現出來的會是近乎完美的圓形,但一旦離赤道越來越遠,(在螢幕上) 看起來就越不像圓形。

加入圓形

下面的代碼片斷添加一個圓形的地圖:

Swift

let circleCenter = CLLocationCoordinate2D(latitude: 37.35, longitude: -122.0)
let circle = GMSCircle(position: circleCenter, radius: 1000)
circle.map = mapView
      

Objective-C

CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(37.35, -122.0);
GMSCircle *circle = [GMSCircle circleWithPosition:circleCenter
                                         radius:1000];
circle.map = mapView;
      

不管是在將圓形加入地圖之前或之後,您都可以自訂圓形的外觀。

自訂圓形

您可以修改 GMSCircle 的屬性,藉此指定自訂顏色和筆劃寬度。它支持下面的選項:

fillColor
UIColor 物件,指定圓形內部顏色。默認為透明。
strokeColor
UIColor 物件會指定圓形外框的顏色。預設值為 blackColor
strokeWidth
圓圈外框的粗細,從螢幕點指向。預設為 1。縮放地圖時,粗細不會縮放。

下列程式碼片段新增一個半透明的紅色圓形,內有半透明紅色內部圖示。

Swift

circle.fillColor = UIColor(red: 0.35, green: 0, blue: 0, alpha: 0.05)
circle.strokeColor = .red
circle.strokeWidth = 5
      

Objective-C

circle.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
circle.strokeColor = [UIColor redColor];
circle.strokeWidth = 5;
      

建立中空的多邊形

您可以在單一 GMSPolygon 物件中組合多個路徑,建立較複雜的形狀,例如填滿的環形或甜甜圈 (多邊形會在多邊形內以獨立形狀顯示)。複雜的形狀是多個路徑的組成。

建立一個路徑,其中包含多邊形涵蓋的最大區域。然後將多邊形的 holes 屬性指定為一或多個 GMSPath 物件的陣列,以定義多邊形內的孔。

如果較小的路徑完全由大型路徑包住,看起來就像是多邊形的某個區域已移除。

以下程式碼範例會建立一個包含兩個孔的多邊形:

Swift

let hydeParkLocation = CLLocationCoordinate2D(latitude: -33.87344, longitude: 151.21135)
let camera = GMSCameraPosition.camera(withTarget: hydeParkLocation, zoom: 16)
let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
mapView.animate(to: camera)

let hydePark = "tpwmEkd|y[QVe@Pk@BsHe@mGc@iNaAKMaBIYIq@qAMo@Eo@@[Fe@DoALu@HUb@c@XUZS^ELGxOhAd@@ZB`@J^BhFRlBN\\BZ@`AFrATAJAR?rAE\\C~BIpD"
let archibaldFountain = "tlvmEqq|y[NNCXSJQOB[TI"
let reflectionPool = "bewmEwk|y[Dm@zAPEj@{AO"

let hollowPolygon = GMSPolygon()
hollowPolygon.path = GMSPath(fromEncodedPath: hydePark)
hollowPolygon.holes = [GMSPath(fromEncodedPath: archibaldFountain)!, GMSPath(fromEncodedPath: reflectionPool)!]
hollowPolygon.fillColor = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.2)
hollowPolygon.strokeColor = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
hollowPolygon.strokeWidth = 2
hollowPolygon.map = mapView
      

Objective-C

CLLocationCoordinate2D hydeParkLocation = CLLocationCoordinate2DMake(-33.87344, 151.21135);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:hydeParkLocation
                                                           zoom:16];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

NSString *hydePark = @"tpwmEkd|y[QVe@Pk@BsHe@mGc@iNaAKMaBIYIq@qAMo@Eo@@[Fe@DoALu@HUb@c@XUZS^ELGxOhAd@@ZB`@J^BhFRlBN\\BZ@`AFrATAJAR?rAE\\C~BIpD";
NSString *archibaldFountain = @"tlvmEqq|y[NNCXSJQOB[TI";
NSString *reflectionPool = @"bewmEwk|y[Dm@zAPEj@{AO";

GMSPolygon *hollowPolygon = [[GMSPolygon alloc] init];
hollowPolygon.path = [GMSPath pathFromEncodedPath:hydePark];
hollowPolygon.holes = @[[GMSPath pathFromEncodedPath:archibaldFountain],
                  [GMSPath pathFromEncodedPath:reflectionPool]];
hollowPolygon.fillColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.2];
hollowPolygon.strokeColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
hollowPolygon.strokeWidth = 2;
hollowPolygon.map = mapView;