我所拥有的:纬度和经度。
我想要什么:获取这些坐标的天气更新。
如果您想使用 Google Weather API,您必须向其传递城市、州或邮政编码。为此,您需要对您的纬度/经度进行地理编码以获取此信息。
这是 Google Weather API 的 URL:http ://www.google.com/ig/api?weather=Seattle,WA
这是一个获取 lat/long 并转换为 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();
}
然后将邮政编码(或城市、州)传递给 Google Weather API 并解析返回的 XML。祝你好运!
google API 已关闭,因此您应该寻找替代方案。 http://openweathermap.org/api
您需要使用 API。你必须自己做一些研究,这是一个很好的。