Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Android GeoJSON

A complete GeoJSON implementation for Android.

Table of Contents


  • Android SDK 8 or Higher


Android Studio / Gradle

dependencies {
  compile ''



Sample Usage

Whether you need to parse existing GeoJSON from a file or web server, or create new GeoJSON from user input, this library has got you covered.

Parsing GeoJSON

If you have existing GeoJSON that you need to parse, you have three source options with this library:

  1. String
  2. JSONObject
  3. InputStream

Once you have your GeoJSON in one of the above formats, simply pass it to GeoJSON#parse.

String string; // A string containing GeoJSON

try {
    GeoJSONObject geoJSON = GeoJSON.parse(string);
catch (JSONException e) {
JSONObject json; // A JSONObject formatted as GeoJSON

GeoJSONObject geoJSON = GeoJSON.parse(json);
InputStream stream; // An InputStream pointing to GeoJSON

try {
    GeoJSONObject geoJSON = GeoJSON.parse(stream);
catch (IOException e) {
catch (JSONException e) {

The returned object instance will be a subclass of GeoJSONObject, depending on the type property of the GeoJSON.

Creating GeoJSON

Parsing existing GeoJSON is only half the fun! Why not create new GeoJSON?! Simply create a new instance of which ever GeoJSONObject sub-type you would like, then call #toJSON on it to get a properly formatted JSONObject instance.

For example, the following sample code creates a GeoJSON Feature with a Point geometry.

// Create geometry
Point point = new Point(38.889462878011365, -77.03525304794312);

// Create feature with geometry
Feature feature = new Feature(point);

// Set optional feature identifier

// Set optional feature properties
feature.setProperties(new JSONObject());

// Convert to formatted JSONObject
JSONObject geoJSON = feature.toJSON();

The resulting GeoJSON can be seen here.