GeoJSON
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Selecciona la plataforma:
Android
iOS
JavaScript
En esta página, se muestra cómo renderizar datos geográficos en el archivo GeoJSON
de formato, con GMUGeoJSONParser
, en
conjunción con GMUGeometryRenderer
. GeoJSON es una herramienta popular
para procesar datos geográficos como puntos, líneas y polígonos.
Requisitos previos y notas
GMUGeoJSONParser
es parte de
la Biblioteca de utilidades del SDK de Maps para iOS Si aún no configuraste
la biblioteca, sigue la guía de configuración antes de leer el resto de esta página.
Para ver la muestra de código completa, consulta las apps de ejemplo
activado
GitHub.
Cómo renderizar datos de GeoJSON
Para renderizar datos de GeoJSON en un mapa, crea un objeto GMUGeoJSONParser
con
la ruta a un recurso GeoJSON (GeoJSON_sample.kml
en este
ejemplo). Luego, crea un GMUGeometryRenderer
y pasa el
Instancia GMUKMLParser
. Por último, llama
GMUGeometryRenderer.render()
El siguiente ejemplo de código muestra
cómo renderizar datos de GeoJSON en un mapa:
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 que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-26 (UTC)
[null,null,["Última actualización: 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```"]]