Get weather update of current location?
Asked Answered
M

3

2

What I have: Latitude and Longitude.

What I want: Get weather update for these coordinates.

Metalanguage answered 4/8, 2011 at 5:23 Comment(0)
B
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!

Bellringer answered 4/8, 2011 at 6:56 Comment(1)
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 APIBellringer
L
2

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

Libertinism answered 3/7, 2014 at 15:30 Comment(3)
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..Metalanguage
And Thank you for yours. i am still in development so i'll be sure to check it out as well. Thank you :)Libertinism
i want to access weather information on the basis of current map extent could u help with this @MetalanguageVilliform
R
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/

Radix answered 4/8, 2011 at 5:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.