Skip to content

Nextome/GeoJsonify

Repository files navigation

GeoJsonify

Simply add GeoJson layers to your Maps


Supported Map Services:

How to use

  1. Add JitPack in your root build.gradle at the end of repositories:
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  1. Add the dependency in your module build.gradle:
	dependencies {
	        compile 'com.github.Nextome:GeoJsonify:v1.0.0'
	}
  1. Simply use the method:
GeoJsonify.geoJsonifyMap(map, List<Uri> jsonUris, int color, Context context);
  • map is the map where the layers will be added. It can be a GoogleMap (Google Maps) / MapboxMap (Mapbox) / MapView (OSM)

  • jsonUris is a list of URIs, each one with a different .geojson file to parse.

  • color is the color of the lines that will be rendered.

Alternativly, you can also specify a different color for each layer using

GeoJsonify.geoJsonifyMap(map, List<Uri> jsonUris, List<Integer> colors, Context context);

Javadoc

Available here.

Example (Google Maps)

Here's a full Google Maps implementation:

public class GoogleMapsActivity extends MapBaseActivity implements OnMapReadyCallback {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getIntentExtras(getIntent());
        setContentView(R.layout.activity_maps);

        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        Uri uri1 = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath() + "italy.geojson"));
        Uri uri2 = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath() + "puglia.geojson"));

        List<Uri> URIs = new ArrayList<>();
        URIs.add(uri1);
        URIs.add(uri2);
        
        try {
            GeoJsonify.geoJsonifyMap(googleMap, URIs, Color.BLACK, this.getContext());
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this.getContext(), "Unable to read file", Toast.LENGTH_SHORT).show();
        } catch (JSONException e) {
            e.printStackTrace();
            Toast.makeText(this.getContext(), "Unable to parse file", Toast.LENGTH_SHORT).show();
        }
    }
}

For more examples with all services, see our example app GeoJson Viewer


GeoJson Viewer

View GeoJson files on your Android Device

Get it on Google Play

How to use

Simply choose a GeoJson file on your device and select a map provider from the list.

Supported Map Services:

Examples

Map with Polygons, Lines and Points

Different Services

Same .geojson file opened with Google Maps, Open Street Map and MapBox

How to build the project

  • Clone the project;
  • Open Android Studio and select Import Project;
  • Add your own Google Maps and Mapbox API keys in strings.xml;

We'll also be happy to accept your pull requests.

Read More

Read more about adding a GeoJson layer on maps on our blog.

Install the app

GeoJson Viewer is available for free on Google Play.

Licence

GeoJson Viewer is licensed under the Apache License 2.0.

Made at Nextome.