GeoJSON

Select platform: Android iOS JavaScript

This page shows you how to render geographic data in the GeoJSON format, using GMUGeoJSONParser , in conjunction with GMUGeometryRenderer . GeoJSON is a popular format for rendering geographic data such as points, lines, and polygons.

Prerequisites and notes

GMUGeoJSONParser is part of the Maps SDK for iOS Utility Library . If you haven't yet set up the library, follow the setup guide before reading the rest of this page.

For the full code sample, see the sample apps on GitHub .

Rendering GeoJSON data

To render GeoJSON data on a map, create a GMUGeoJSONParser with the path to a GeoJSON resource ( GeoJSON_sample.kml in this example). Then, create a GMUGeometryRenderer , passing the GMUKMLParser instance. Finally, call GMUGeometryRenderer.render() . The following code example shows rendering GeoJSON data on a map:

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 
  
Create a Mobile Website
View Site in Mobile | Classic
Share by: