Android GeoJSON Library


License

License

Categories

Categories

Geo Business Logic Libraries Geospatial JSON Data
GroupId

GroupId

com.cocoahero.android
ArtifactId

ArtifactId

geojson
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

aar
Description

Description

Android GeoJSON Library
Android GeoJSON Library
Project URL

Project URL

https://github.com/cocoahero/android-geojson
Source Code Management

Source Code Management

https://github.com/cocoahero/android-geojson

Download geojson

How to add to project

<!-- https://jarcasting.com/artifacts/com.cocoahero.android/geojson/ -->
<dependency>
    <groupId>com.cocoahero.android</groupId>
    <artifactId>geojson</artifactId>
    <version>1.0.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.cocoahero.android/geojson/
implementation 'com.cocoahero.android:geojson:1.0.1'
// https://jarcasting.com/artifacts/com.cocoahero.android/geojson/
implementation ("com.cocoahero.android:geojson:1.0.1")
'com.cocoahero.android:geojson:aar:1.0.1'
<dependency org="com.cocoahero.android" name="geojson" rev="1.0.1">
  <artifact name="geojson" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.cocoahero.android', module='geojson', version='1.0.1')
)
libraryDependencies += "com.cocoahero.android" % "geojson" % "1.0.1"
[com.cocoahero.android/geojson "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Android GeoJSON

A complete GeoJSON implementation for Android.

Table of Contents

Requirements

  • Android SDK 8 or Higher

Installation

Android Studio / Gradle

dependencies {
  compile 'com.cocoahero.android:geojson:1.0.1@jar'
}

Maven

<dependency>
  <groupId>com.cocoahero.android</groupId>
  <artifactId>geojson</artifactId>
  <version>1.0.1</version>
  <type>jar</type>
</dependency>

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 string; // A string containing GeoJSON

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

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

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

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
feature.setIdentifier("MyIdentifier");

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

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

The resulting GeoJSON can be seen here.

Versions

Version
1.0.1
1.0.0