How to get the place name by latitude and longitude using openstreetmap in android

Posted by Gaurav kumar on Stack Overflow See other posts from Stack Overflow or by Gaurav kumar
Published on 2013-10-19T09:52:45Z Indexed on 2013/10/19 9:53 UTC
Read the original article Hit count: 307

Filed under:
|
|

In my app i am using osm rather than google map.I have latitude and longitude.So from here how i will query to get the city name from osm database..please help me.

final String requestString =
         "http://nominatim.openstreetmap.org/reverse?format=json&lat=" +
         Double.toString(lat) + "&lon=" + Double.toString(lon) +
         "&zoom=18&addressdetails=1";

         RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
         URL.encode(requestString));
         try {
         @SuppressWarnings("unused")
         Request request = builder.sendRequest(null, new RequestCallback()
         {
         @Override
         public void onResponseReceived(Request request, Response
         response) {
         if (response.getStatusCode() == 200) {
         String city = "";
         try {
         JSONValue json = JSONParser.parseStrict(response);
         JSONObject address = json.isObject().get("address").isObject();
         final String quotes = "^\"|\"$";

         if (address.get("city") != null) {
         city = address.get("city").toString().replaceAll(quotes, "");
         } else if (address.get("village") != null) {
         city = address.get("village").toString().replaceAll(quotes, "");
         }
         } catch (Exception e) {
         }
         }
         }
         });
         } catch (Exception e1) {
         }

© Stack Overflow or respective owner

Related posts about android

Related posts about location