2

What I have: Latitude and Longitude.

What I want: Get weather update for these coordinates.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Noman
  • 4,049
  • 10
  • 38
  • 59

3 Answers3

3

If you want to use the Google Weather API, you'll have to pass it either a City, State or a Zip code. To do this, you'll need to GeoCode your lat/long to get this info.

Here's the URL to the Google Weather API: http://www.google.com/ig/api?weather=Seattle,WA

Here's a sample code to take lat/long and convert to zip:

Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);

List<Address> addresses = null;

try {
    addresses = geocoder.getFromLocation(latitude, longitude, 3);
} catch (IOException ex) {
    //Handle IOException
}

for (int i = 0; i < addresses.size(); i++) {
    Address address = addresses.get(i);
    if (address.getPostalCode() != null)
        String zipCode = address.getPostalCode();
}

Then pass the Zip Code (Or City, State) to the Google Weather API and parse the returning XML. Good luck!

hooked82
  • 6,336
  • 4
  • 41
  • 46
  • Yes, this is a snippet of code, cut down for visibility purposes that I use in my app. You can see it in the app screenshots if you go to the Market and serach for "My Fishing Companion". The data (other than images and sunrise/sunset) all comes from the Google Weather API – hooked82 Aug 04 '11 at 07:26
2

google API is down, so you should look for an alternative. http://openweathermap.org/api

  • Thank you for response.. It was a very old question and i did my task with yahoo weather api's .. But i will look into it in future if needed.. – Noman Jul 04 '14 at 06:24
  • 1
    And Thank you for yours. i am still in development so i'll be sure to check it out as well. Thank you :) – amruzzzzzzzzzi Jul 08 '14 at 08:39
  • i want to access weather information on the basis of current map extent could u help with this @Noman – Sarah Salar Jul 03 '17 at 08:19
1

You need to use an API. You'll have to do some research on your own, here's one good one.

http://www.weather.gov/xml/

Slicekick
  • 2,119
  • 5
  • 24
  • 35