GithubHelp home page GithubHelp logo

awaiskhansar / android-geojson Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cocoahero/android-geojson

0.0 2.0 0.0 423 KB

A complete GeoJSON implementation for Android.

License: MIT License

Java 100.00%

android-geojson's Introduction

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.

android-geojson's People

Contributors

bleege avatar cocoahero avatar ligi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.