Take the 2-minute tour ×

In my application i want to get the weather report I'm using http://www.google.com/ig/api?weather="" for that by providing a city. But for me only lat and longitude is available

How can I get the place name by lat and longitudes.

share|improve this question
just a tip: using a sentence with any combination of the words "send me teh codez plz" is a BAD idea and is unwanted on stackoverflow. –  Epaga Mar 2 '10 at 14:13
But do the extra words really invalidate the question? Can we not help him with his problem of parsing xml strings and suggest a low-effort path for his development? –  Kieveli Mar 2 '10 at 14:26
@Kieveli Good point. I just removed all the noise and now the question reads a lot better. :) –  Epaga Mar 2 '10 at 14:43
add comment

5 Answers

up vote 3 down vote accepted

FYI, what you're doing is called reverse geocoding.

Most of the Geonames webservices are available in JSON, including findNearby.

Google also has a reverse geocoding webservice

What you're asking is not a small thing - a lat/lng database is almost certainly going to be presented in either XML or JSON, so it might be worth investing a little time and effort in this. Android must have xml/json wrappers?

share|improve this answer
It isn't too difficult to parse the XML - you don't do it yourself, you use a library. Often you can get it working within 1-2 days of effort! –  Kieveli Mar 2 '10 at 14:27
add comment

There's no need to invoke the Geocoder, in this weather API, which BTW is not public so you should use it with caution, city, state and country are only informational fields, so you can use it like this (dummy constants):

private static final String URL = "http://www.google.com/ig/api?weather=%s,%s,%s,%d,%d";

final String url = String.format(URL, "city", "state", "country",
   p.getLatitudeE6(), p.getLongitudeE6());
share|improve this answer
add comment

You can use the Location API to get a Address Object and get the locality from there

share|improve this answer
Great link. Love this answer. I just got an Android last week. Now I want to code for it =) –  Kieveli Mar 2 '10 at 14:47
add comment

Android has a class called Geocoder for this stuff. Look at the getFromLocation method.

share|improve this answer
add comment

Pass the latitude and longitude in your method and get the corresponding place name. Don't forget the user permissions:

public static String getUserLocation(String lat, String lon) {
   String userlocation = null;
   String readUserFeed = readUserLocationFeed(lat.trim() + "," + lon.trim());
   try {
      JSONObject Strjson = new JSONObject(readUserFeed);
      JSONArray jsonArray = new JSONArray(Strjson.getString("results"));
      userlocation = jsonArray.getJSONObject(1)
   } catch (Exception e) {
   Log.i("User Location ", userlocation);
   return userlocation;

public static String readUserLocationFeed(String address) {
   StringBuilder builder = new StringBuilder();
   HttpClient client = new DefaultHttpClient();
   HttpGet httpGet = new HttpGet(
         "http://maps.google.com/maps/api/geocode/json?latlng=" + address
               + "&sensor=false");
   try {
      HttpResponse response = client.execute(httpGet);
      StatusLine statusLine = response.getStatusLine();
      int statusCode = statusLine.getStatusCode();
      if (statusCode == 200) {
         HttpEntity entity = response.getEntity();
         InputStream content = entity.getContent();
         BufferedReader reader = new BufferedReader(new InputStreamReader(
         String line;
      } else {
         Log.e(ReverseGeocode.class.toString(), "Failed to download file");
   } catch (ClientProtocolException e) {
   } catch (IOException e) {
   return builder.toString();
share|improve this answer
add comment

Your Answer


