Google 地圖平台即將推出新版地圖樣式。新版地圖樣式內建全新的預設調色盤,並且提升地圖體驗、改善服務的可用性。所有地圖樣式都將於 2025 年 3 月自動更新。請參閱「
Google 地圖平台新版地圖樣式」一文,進一步瞭解適用範圍及如何提早啟用。
GeoJSON
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何以 GeoJSON 呈現地理資料
格式,使用 GMUGeoJSONParser
,在
搭配 GMUGeometryRenderer
。GeoJSON 是一種
格式,用來呈現點、線與多邊形等地理資料。
必要條件和注意事項
「GMUGeoJSONParser
」隸屬於
Maps SDK for iOS 公用程式庫。如果尚未設定
程式庫,請先按照設定指南操作,再閱讀本頁面的其餘內容。
如需完整程式碼範例,請參閱範例應用程式
已開啟
GitHub。
轉譯 GeoJSON 資料
如要在地圖上算繪 GeoJSON 資料,請建立 GMUGeoJSONParser
GeoJSON 資源的路徑 (其中 GeoJSON_sample.kml
範例)。然後建立 GMUGeometryRenderer
,將
GMUKMLParser
執行個體。最後,呼叫
GMUGeometryRenderer.render()
。以下程式碼範例顯示
在地圖上呈現 GeoJSON 資料:
Swift
import GoogleMapsUtils
class GeoJSON {
private var mapView: GMSMapView!
func renderGeoJSON() {
guard let path = Bundle.main.path(forResource: "GeoJSON_sample", ofType: "json") else {
return
}
let url = URL(fileURLWithPath: path)
let geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()
let renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)
renderer.render()
}
}
Objective-C
@import GoogleMapsUtils;
@implementation GeoJSON {
GMSMapView *_mapView;
}
- (void)renderGeoJSON {
NSString *path = [[NSBundle mainBundle] pathForResource:@"GeoJSON_sample" ofType:@"json"];
NSURL *url = [NSURL fileURLWithPath:path];
GMUGeoJSONParser *parser = [[GMUGeoJSONParser alloc] initWithURL:url];
[parser parse];
GMUGeometryRenderer *renderer = [[GMUGeometryRenderer alloc] initWithMap:_mapView
geometries:parser.features];
[renderer render];
}
@end
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-05 (世界標準時間)。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"缺少我需要的資訊"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"過於複雜/步驟過多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"過時"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻譯問題"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/程式碼問題"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"容易理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"確實解決了我的問題"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
{"lastModified": "\u4e0a\u6b21\u66f4\u65b0\u6642\u9593\uff1a2024-09-05 (\u4e16\u754c\u6a19\u6e96\u6642\u9593)\u3002"}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-09-05 (世界標準時間)。"]]