I am trying to use Google\'s unofficial weather API in an Android Application.
I use this code:
//get the text from the edit text
userZip = zipCo
I think you need to open the connection with the url and get the inputstream for this to work. I would try this:
URL googleWeatherService = null;
URLConnection conn = null;
try {
googleWeatherService = new URL(link);
conn = googleWeatherService.openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
SAXBuilder parser = new SAXBuilder();
try {
doc = parser.build(conn.getInputStream());
Hopefully this does the trick for you!
Otherwise if this fails, it sounds like you're having to deal with URL redirects, which is a problem i used to have. You would need to do the following in that case:
URL googleWeatherService = null;
URLConnection conn = null;
try {
googleWeatherService = new URL(link);
HttpURLConnection ucon = (HttpURLConnection) googleWeatherService.openConnection();
ucon.setInstanceFollowRedirects(false);
URL secondURL = new URL(ucon.getHeaderField("Location"));
conn = secondURL.openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
SAXBuilder parser = new SAXBuilder();
try {
doc = parser.build(conn.getInputStream());
Hope this solves it!