views:

122

answers:

4

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.

+1  A: 

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?

adam
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
+2  A: 

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

Donal Rafferty
Great link. Love this answer. I just got an Android last week. Now I want to code for it =)
Kieveli
A: 

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

neon
A: 

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());
dtmilano