GeoJSON
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Wybierz platformę:
Android
iOS
JavaScript
Na tej stronie dowiesz się, jak renderować dane geograficzne w formacie GeoJSON
w formacie GMUGeoJSONParser
, w formacie
spójnik z GMUGeometryRenderer
. GeoJSON jest popularny
do renderowania danych geograficznych, takich jak punkty, linie i wielokąty.
Wymagania wstępne i uwagi
GMUGeoJSONParser
należy do:
bibliotekę narzędziową pakietu Maps SDK na iOS. Jeśli nie masz jeszcze skonfigurowanego
z biblioteki, postępuj zgodnie z przewodnikiem konfiguracji, zanim przeczytaj dalszą część tej strony.
Pełny przykładowy kod znajdziesz w sekcji z przykładowymi aplikacjami
wł.
GitHub.
Renderowanie danych GeoJSON
Aby wyrenderować dane GeoJSON na mapie, utwórz GMUGeoJSONParser
z
ścieżkę do zasobu GeoJSON (GeoJSON_sample.kml
w tym
). Następnie utwórz GMUGeometryRenderer
, przekazując w odpowiedzi
GMUKMLParser
instancję. Na koniec wywołaj
GMUGeometryRenderer.render()
Oto przykładowy kod
renderowanie danych GeoJSON na mapie:
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
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-26 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-26 UTC."],[[["\u003cp\u003eThis page demonstrates how to render geographic data in GeoJSON format on Google Maps using the \u003ccode\u003eGMUGeoJSONParser\u003c/code\u003e and \u003ccode\u003eGMUGeometryRenderer\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eGeoJSON is a commonly used format for displaying geographic data like points, lines, and polygons.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need to set up the Maps SDK for iOS Utility Library before using \u003ccode\u003eGMUGeoJSONParser\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples show how to render GeoJSON data on a map in both Swift and Objective-C.\u003c/p\u003e\n"]]],["The document explains how to render GeoJSON data on a map using the `GMUGeoJSONParser` and `GMUGeometryRenderer` from the Maps SDK for iOS Utility Library. First, a `GMUGeoJSONParser` is created with the GeoJSON resource path. Then, a `GMUGeometryRenderer` is initialized with the map view and the parser's features. Finally, the `GMUGeometryRenderer.render()` method is called to display the GeoJSON data, such as points, lines, and polygons, on the map.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/geojson \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/geojson \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/datalayer \"View this page for the JavaScript platform docs.\")\n\nThis page shows you how to render geographic data in the GeoJSON\nformat, using `GMUGeoJSONParser`, in\nconjunction with `GMUGeometryRenderer`. GeoJSON is a popular\nformat for rendering geographic data such as points, lines, and polygons.\n\nPrerequisites and notes\n\n`GMUGeoJSONParser` is part of\nthe [Maps SDK for iOS Utility Library](https://github.com/googlemaps/google-maps-ios-\nutils). If you haven't yet set up\nthe library, follow the [setup guide](/maps/documentation/ios-\nsdk/utility/setup) before reading the rest of this page.\n\nFor the full code sample, see the sample apps\n[on\nGitHub](https://github.com/googlemaps/google-maps-ios-utils).\n\nRendering GeoJSON data\n\nTo render GeoJSON data on a map, create a `GMUGeoJSONParser` with\nthe path to a GeoJSON resource (`GeoJSON_sample.kml` in this\nexample). Then, create a `GMUGeometryRenderer`, passing the\n`GMUKMLParser` instance. Finally, call\n`GMUGeometryRenderer.render()`. The following code example shows\nrendering GeoJSON data on a map: \n\nSwift \n\n```swift\nimport GoogleMapsUtils\n\nclass GeoJSON {\n private var mapView: GMSMapView!\n\n func renderGeoJSON() {\n guard let path = Bundle.main.path(forResource: \"GeoJSON_sample\", ofType: \"json\") else {\n return\n }\n\n let url = URL(fileURLWithPath: path)\n\n let geoJsonParser = GMUGeoJSONParser(url: url)\n geoJsonParser.parse()\n\n let renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)\n renderer.render()\n }\n}\n \n```\n\nObjective-C \n\n```objective-c\n@import GoogleMapsUtils;\n\n@implementation GeoJSON {\n GMSMapView *_mapView;\n}\n\n- (void)renderGeoJSON {\n NSString *path = [[NSBundle mainBundle] pathForResource:@\"GeoJSON_sample\" ofType:@\"json\"];\n NSURL *url = [NSURL fileURLWithPath:path];\n GMUGeoJSONParser *parser = [[GMUGeoJSONParser alloc] initWithURL:url];\n [parser parse];\n GMUGeometryRenderer *renderer = [[GMUGeometryRenderer alloc] initWithMap:_mapView\n geometries:parser.features];\n [renderer render];\n}\n\n@end\n \n```"]]