Java android show osrm json on map

0

This is my osrm json:

{"code":"Ok","trips":[{"legs":[{"steps":[],"distance":0,"duration":0,"summary":"","weight":0},{"steps":[],"distance":0,"duration":0,"summary":"","weight":0},{"steps":[],"distance":0,"duration":0,"summary":"","weight":0}],"distance":0,"duration":0,"weight_name":"routability","weight":0}],"waypoints":[{"waypoint_index":0,"trips_index":0,"location":[14.108669,52.83694],"name":"Neuglietzener Straße","distance":60315.735991,"hint":"mGsGgKmeIIAAAAAAsQAAAAAAAADAAAAAAAAAAJeidkIAAAAAimLZQgAAAABZAAAAAAAAAGAAAAD6CgCA_UfXAEw6JgM8TMwArVghAwAAXwSBbiAb"},{"waypoint_index":1,"trips_index":0,"location":[14.108669,52.83694],"name":"Neuglietzener Straße","distance":59029.088208,"hint":"mGsGgKmeIIAAAAAAsQAAAAAAAADAAAAAAAAAAJeidkIAAAAAimLZQgAAAABZAAAAAAAAAGAAAAD6CgCA_UfXAEw6JgOCbswA_4ghAwAAXwSBbiAb"},{"waypoint_index":2,"trips_index":0,"location":[14.108669,52.83694],"name":"Neuglietzener Straße","distance":57751.361626,"hint":"mGsGgKmeIIAAAAAAsQAAAAAAAADAAAAAAAAAAJeidkIAAAAAimLZQgAAAABZAAAAAAAAAGAAAAD6CgCA_UfXAEw6JgNL58wA03AhAwAAXwSBbiAb"}]}

I try to show this on a map. I did this:

static void geoJsonifyMap(final MapView map, List<Uri> jsonUris, List<Integer> jsonColors, Context context) throws IOException {
    final KmlDocument kmlDocument = new KmlDocument();

    for (int i=0; i<jsonUris.size(); i++) {
        Uri uri = jsonUris.get(i);
        kmlDocument.parseGeoJSON(FileUtils.getStringFromFile(uri, context));

        Drawable defaultMarker = context.getResources().getDrawable(R.drawable.marker_default);
        Bitmap defaultBitmap = ((BitmapDrawable) defaultMarker).getBitmap();
        Style defaultStyle = new Style(defaultBitmap, jsonColors.get(i), 2f, 0x00000000);
        FolderOverlay geoJsonOverlay = (FolderOverlay) kmlDocument.mKmlRoot.buildOverlay(map, defaultStyle, null, kmlDocument);

        map.getOverlays().add(geoJsonOverlay);
        map.invalidate();
    }

    map.addOnFirstLayoutListener(new MapView.OnFirstLayoutListener() {
        @Override
        public void onFirstLayout(View v, int left, int top, int right, int bottom) {
            BoundingBox boundingBox = kmlDocument.mKmlRoot.getBoundingBox();
            map.zoomToBoundingBox(boundingBox, false);
            map.zoomToBoundingBox(boundingBox, false);
            map.invalidate();
        }
    });
}

But my application is crashed and in logs I see ;

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference

I do not have an idea of what I did wrong. I see this file But I can not sho this on a map

java
android
asked on Stack Overflow Feb 14, 2019 by Kala • edited Feb 14, 2019 by Tanveer Munir

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0