Android Weather Forecast - Google Weather API - Description

Tutorials with advanced 'difficulty' and more Lines of Code.

Postby plusminus » Tue Feb 26, 2008 11:47 am

Hello to__liuyi,

here:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity android:name="WeatherForecast" android:label="@string/app_name">
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

a Dot is missing:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <activity android:name=".WeatherForecast" android:label="@string/app_name">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Also check if somewhere is "WeatherForcast" instead of "WeatherForecast".

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

tried

Postby to__liuyi » Wed Feb 27, 2008 2:31 am

I have tried to add the dot, it doesn't work. And I checked spelling of Weatherforecast.
to__liuyi
Freshman
Freshman
 
Posts: 4
Joined: Mon Feb 04, 2008 3:47 am

Postby plusminus » Thu Feb 28, 2008 2:24 am

Hello to__liuyi,

I attached the working source to the end of this post: viewtopic.php?p=1304#1304

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby to__liuyi » Thu Feb 28, 2008 3:08 am

well done! good job!
to__liuyi
Freshman
Freshman
 
Posts: 4
Joined: Mon Feb 04, 2008 3:47 am

weather Info

Postby shriya » Fri Aug 08, 2008 10:12 am

If we use the Google RSS feed to take the weather data do we need to show the google trademark on our site?

It will be really helpful if I get reply immediately?


Thanks,
Shriya
shriya
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Aug 08, 2008 10:05 am

Postby jujudellago » Sat Sep 13, 2008 12:00 pm

plusminus wrote:Hello icer,

the weather Data is openly provided by Google and therefore we can us it for free.
I don't know whether there is any document out there describing how to use the API, just use it ;)

Regards,
plusminus


Hi,

I found this very interresting topic while googling for a solution to have a dynamic weather forecast solution in a web app.

I have adapted the principle to a ruby system fetching and caching the results of the query, then parsing it with XMLSimple.

It worked really well, I just had time to run a few tests before everything got messed up... queries in my browser such as
http://www.google.com/ig/api?weather=geneva,switzerland give me no error, but fetching the datas from my program, with the same queries return something like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0"><problem_cause data=""/></weather></xml_api_reply>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4



I did not find any information on the usage of the weather API, so my feeling is that google doesn't allow such queries ... does anyone use this service ? I would love to "just use it" but I'm sure the google people are just smarter than me....

regards

julien
jujudellago
Freshman
Freshman
 
Posts: 3
Joined: Sat Sep 13, 2008 11:49 am

Top

Postby plusminus » Sat Sep 13, 2008 2:53 pm

jujudellago wrote:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0"><problem_cause data=""/></weather></xml_api_reply>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


:shock: Same with me here, two days ago it was still working :(

I'll see if I can find something...

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby plusminus » Sat Sep 13, 2008 2:58 pm

Using a zipcode, I receive:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <xml_api_reply version="1">
  2.  
  3. <weather module_id="0" tab_id="0">
  4.  
  5. <problem_cause data="Information is temporarily unavailable."/>
  6.  
  7. </weather>
  8.  
  9. </xml_api_reply>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

So lets hope its only temporary!
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby jujudellago » Sat Sep 13, 2008 4:07 pm

plusminus wrote: :shock: Same with me here, two days ago it was still working :(

I'll see if I can find something...

Regards,
plusminus


wow just 2 days ? I felt like these google weather tricks would just bring me troubles, and as I'm very bored today, I played around with the weather.com services...

http://www.weather.com/services/xmloap.html

not so easy to use as the google one, but it gives more complete results... well if the google weather gives you problems you can try...

regards

julien
jujudellago
Freshman
Freshman
 
Posts: 3
Joined: Sat Sep 13, 2008 11:49 am

Postby plusminus » Sun Sep 14, 2008 12:11 am

jujudellago wrote:
plusminus wrote: :shock: Same with me here, two days ago it was still working :(

I'll see if I can find something...

Regards,
plusminus


wow just 2 days ? I felt like these google weather tricks would just bring me troubles, and as I'm very bored today, I played around with the weather.com services...

http://www.weather.com/services/xmloap.html

not so easy to use as the google one, but it gives more complete results... well if the google weather gives you problems you can try...

regards

julien


Can it resolve weather for Latitude/Longitude pairs?
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby jujudellago » Sun Sep 14, 2008 1:00 pm

plusminus wrote:Can it resolve weather for Latitude/Longitude pairs?


No, that's the "not so easy part", the queries must be made with a specific city ID, so you must fetch the city ID from a given city.

I did not find a city database for weather.com, so I populated the maxmind city database http://www.maxmind.com/app/city then I internally calculate the nearest city to query weather.com (it's all made very easy with some ruby on rails plugins...)
jujudellago
Freshman
Freshman
 
Posts: 3
Joined: Sat Sep 13, 2008 11:49 am

Problem connecting to the weather

Postby cmveas » Wed Oct 22, 2008 12:21 am

Hello Plusminus I was trying to make the example work but I have a problem when I tried to connect to the "service"

http://www.google.com/ig/api?weather=



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String cityParamString = ((EditText) findViewById(R.id.edit_input))
  2.                                                         .getText().toString();
  3.                                         String queryString = "http://www.google.com/ig/api?weather="
  4.                                                         + cityParamString;
  5.                                         /* Replace blanks with HTML-Equivalent. */
  6.                                         url = new URL(queryString.replace(" ", "%20"));
  7.  
  8.                                         /* Get a SAXParser from the SAXPArserFactory. */
  9.                                         SAXParserFactory spf = SAXParserFactory.newInstance();
  10.                                         SAXParser sp = spf.newSAXParser();
  11.  
  12.                                         /* Get the XMLReader of the SAXParser we created. */
  13.                                         XMLReader xr = sp.getXMLReader();
  14.  
  15.                                         /*
  16.                                          * Create a new ContentHandler and apply it to the
  17.                                          * XML-Reader
  18.                                          */
  19.                                         GoogleWeatherHandler gwh = new GoogleWeatherHandler();
  20.                                         xr.setContentHandler(gwh);
  21.                                         InputStream input = url.openStream();  ---> EXCEPTION OCCURS HERE
  22.                                         /* Parse the xml-data our URL-call returned. */
  23.                                         xr.parse(new InputSource(input));
Parsed in 0.033 seconds, using GeSHi 1.0.8.4



I debugged the code and when the line InputStream input = url.openStream(); executes in throws and exception. The monitor showed me this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. 10-21 23:00:19.182: ERROR/WeatherForcaster(169): java.net.SocketException: <span style="font-weight: bold"><span style="text-decoration: underline">unknown error</span></span>
  2. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method)
  3. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:79)
  4. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:59)
  5. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at java.net.Socket.checkClosedAndCreate(Socket.java:763)
  6. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at java.net.Socket.connect(Socket.java:910)
  7. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:61)
  8. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
  9. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
  10. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:800)
  11. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:786)
  12. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1030)
  13. 10-21 23:00:19.182: ERROR/WeatherForcaster(169):     at java.net.URL.openStream(URL.java:664)
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


I tested the connectivity with the emulator but I can perform any search with it so I think that the internet conection must be working well so that leaves me without a clue about what must be wrong. By the way Im running the example with SDK 1.0 I hope that helps.
Any suggestion will be welcome and thanks for making available all these examples.
cmveas
Freshman
Freshman
 
Posts: 2
Joined: Mon Oct 20, 2008 6:46 pm

Postby plusminus » Wed Oct 22, 2008 1:15 am

Hi cmveas,

did you add the ACCESS_INTERNET Permission to the AndroidManifest.xml :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Perfect!!

Postby cmveas » Wed Oct 22, 2008 3:41 am

Thanks plusminus I did not know that! and it worked perfectly. Thanks for the help!
Claudio Veas (cmveas)
cmveas
Freshman
Freshman
 
Posts: 2
Joined: Mon Oct 20, 2008 6:46 pm

Postby jeffy2010 » Tue Nov 18, 2008 3:34 pm

Hi plusminus, I am somehow not able to run your application. :(
I have attached the console window with the error (error1.jpg).
It would be really helpful if you could tell me if I am missing out on something.

Thank you so much,
Jeff
Attachments
error1.JPG
error1.JPG (207.96 KiB) Viewed 8766 times
jeffy2010
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 18, 2008 3:28 pm

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests