Get weather update of current location?

為{幸葍}努か 提交于 2019-12-04 17:58:44

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!

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

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/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!