Search code examples
androidjsonopenstreetmap

Parse Json data OSM


I'm working to create an application, for get address without geocode by google. I found json data from OSM (openstreetmap), this is the link https://nominatim.openstreetmap.org/reverse?format=json&lat=-7.740601&lon=110.3333017&zoom=18&addressdetails=1

{  
   "place_id":"234438878",
   "licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright",
   "osm_type":"way",
   "osm_id":"585612977",
   "lat":"-7.74078232331096",
   "lon":"110.333420400495",
   "display_name":"Tlogoadi, Mlati, Sleman, Daerah Istimewa Yogyakarta, 55284, Indonesia",
   "address":{  
      "county":"Tlogoadi",
      "state_district":"Sleman",
      "state":"Daerah Istimewa Yogyakarta",
      "postcode":"55284",
      "country":"Indonesia",
      "country_code":"id"
   },
   "boundingbox":[  ]
}

my question is how to get display_name (single data) on above json format to Android ?


Solution

  • Try this

    try 
    {
        JSONObject jsonObject = new JSONObject(response);
    
        String displayName = jsonObject.getString("display_name")
    
        Log.e("Display Name",":"+ displayName);
    }
    catch (JSONException e) 
    {
        e.printStackTrace();
    }
    

    OUTPUT:

    enter image description here