Get weather update of current location?

2020-07-24 04:44发布

What I have: Latitude and Longitude.

What I want: Get weather update for these coordinates.

3条回答
Viruses.
2楼-- · 2020-07-24 05:05

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!

查看更多
虎瘦雄心在
3楼-- · 2020-07-24 05:15

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

查看更多
等我变得足够好
4楼-- · 2020-07-24 05:19

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/

查看更多
登录 后发表回答