获取当前位置的天气更新? [英] Get weather update of current location?

查看:175
本文介绍了获取当前位置的天气更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:目前我的应用程序是通过GPS回到了我所在位置的坐标

What i have: currently my app is returning me the coordinates of my location through gps.

我要的:获取所获取的当前位置的天气更新

What i want: get weather update of the fetched current location.

推荐答案

如果你想使用谷歌API的天气,你必须将它传递任何一个城市,州或Zip code。要做到这一点,你需要GEO code的纬度/经度来获得这些信息。

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.

下面的网址到谷歌天气API: http://www.google .COM / IG / API?天气=西雅图,华盛顿

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

下面是一个示例code采取纬度/经度并转换为ZIP:

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

然后通过邮编code(或市,州)的谷歌天气API和解析返回XML。祝你好运!

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

这篇关于获取当前位置的天气更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆