【发布时间】:2011-06-26 05:29:47
【问题描述】:
我正在尝试在 Android 应用程序中使用 Google 的非官方天气 API。
我使用这个代码:
//get the text from the edit text
userZip = zipCode.getText().toString();
//create a link using the zip code
//TODO sanitize input
System.out.println(userZip);
link = "http://www.google.com/ig/api?weather=" + userZip;
System.out.println(link);
//connect to the link
URL googleWeatherService = null;
try {
googleWeatherService = new URL(link);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
SAXBuilder parser = new SAXBuilder();
try {
doc = parser.build(googleWeatherService);
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但我收到错误 java.io.IOException 无法打开 http://www.google.com/ig/api?weather=08003(仅以 08003 为例)。
如果你转到 FF 中的链接,你会得到一个很好的 XML 天气文件,那我做错了什么?
【问题讨论】: