GeoJSON
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Seleziona la piattaforma:
Android
iOS
JavaScript
Questa pagina mostra come eseguire il rendering dei dati geografici in GeoJSON
utilizzando GMUGeoJSONParser
, in
in combinazione con GMUGeometryRenderer
. GeoJSON è un modo diffuso
per il rendering di dati geografici come punti, linee e poligoni.
Prerequisiti e note
GMUGeoJSONParser
fa parte di
la libreria di utilità di Maps SDK for iOS. Se non l'hai ancora fatto,
Nella libreria, segui la guida alla configurazione prima di leggere il resto di questa pagina.
Per l'esempio di codice completo, vedi le app di esempio
attivata
GitHub.
Rendering dei dati GeoJSON
Per visualizzare i dati GeoJSON su una mappa, crea un elemento GMUGeoJSONParser
con
del percorso di una risorsa GeoJSON (GeoJSON_sample.kml
in
esempio). Poi, crea un GMUGeometryRenderer
, passando il valore
GMUKMLParser
istanza. Infine, richiama
GMUGeometryRenderer.render()
. L'esempio di codice che segue mostra
visualizzando i dati GeoJSON su una mappa:
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
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 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```"]]