Raghunandan is right. However, if your goal is simply to get "long_name", locality, etc. Using the Google Maps API, you can try the following way to get it. You can get the answer in the form of JSON, which seems to me to be more structured. You can try the URL first: http://maps.google.com/maps/api/geocode/json?latlng=23.0043673,72.5411868999996&sensor=false
I use the following method all the time and it works for me. This may help you get what you are trying:
You can get the latitude and longitude, and then query the Google servers to respond using a JSON object containing various information about the location coordinates. Here is the function:
public JSONObject getLocationInfo( double lat, double lng) { HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false"); HttpClient client = new DefaultHttpClient(); HttpResponse response; StringBuilder stringBuilder = new StringBuilder(); try { response = client.execute(httpGet); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); int b; while ((b = stream.read()) != -1) { stringBuilder.append((char) b); } } catch (ClientProtocolException e) { } catch (IOException e) { } JSONObject jsonObject = new JSONObject(); try { jsonObject = new JSONObject(stringBuilder.toString()); } catch (JSONException e) { e.printStackTrace(); } return jsonObject; }
Now you can parse JSON to get whatever you want. For example, suppose you want a full formatted_address, here is how you can get:
// get lat and lng value JSONObject ret = getLocationInfo(lat, lng); JSONObject location; String location_string; try { //Get JSON Array called "results" and then get the 0th complete object as JSON location = ret.getJSONArray("results").getJSONObject(0); // Get the value of the attribute whose name is "formatted_string" location_string = location.getString("formatted_address"); Log.d("test", "formattted address:" + location_string); } catch (JSONException e1) { e1.printStackTrace(); }
If you want to know more about how to extract the necessary data from the JSON type that you get in response, see the answers on Android - how to parse JSONObject and JSONArrays question. Hope this helps you.
Update
I hope you read the answers to the above question. Now, for example: If you want to get JSON Array from address_components , then just do something like
JSONArray addressComp = ret.getJSONArray("results").getJSONObject(0).getJSONArray("address_components");
Now you can get the first long_name as follows:
String long_name1 = addressComp.getJSONObject(0).getString("long_name");
So try to compare the template here with the JSON response you get. This will allow you to figure out how to go about getting any item. Here, the result was JSONARray, so I got it as a JSONArray. Then I took the first JSONArray result object, whose name was address_components and value was another JSONArray. Then, because I wanted to get the first long_name , so I took the first address_component JSONArray again and asked to get the value component whose name was long_name . I hope you now understand a little how you can read values.
PS: I did not run the last two lines, but formulated logically. Hope this makes you understand. All the best!