我拥有的:纬度和经度。
我想要的:获取这些坐标的天气更新。
最佳答案
如果您想使用 Google Weather API,则必须向其传递城市、州或邮政编码。为此,您需要对纬度/经度进行地理编码才能获取此信息。
以下是 Google Weather API 的 URL:http://www.google.com/ig/api?weather=Seattle,WA
以下是获取纬度/经度并将其转换为 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。祝你好运!
关于android - 获取当前位置的天气更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6936541/