andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

Android Weather Forecast - Google Weather API - Description

Goto page Previous  1, 2, 3, 4  Next
 
       anddev.org - Android Development Community | Android Tutorials | Index -> Advanced Tutorials
Author Message
MrSnowflake
Moderator
Moderator


Joined: 16 Feb 2008
Posts: 1437
Location: Flanders, Belgium

PostPosted: Tue Nov 18, 2008 3:49 pm    Post subject: Reply with quote

Something is wrong with your layout xml, SingleWheatherInfoView can't be found. That's what you callstack says.
Back to top
View user's profile Send private message
jeffy2010
Freshman
Freshman


Joined: 18 Nov 2008
Posts: 5

PostPosted: Tue Nov 18, 2008 4:00 pm    Post subject: Reply with quote

Yes MrSnowflake..
When I open my main.xml on the layout view, it says the following

NoSuchMethodException:org.anddev.android.weatherforecast.views.SingleWeatherInfoView.<init>(android.content.Context, android.util.AttributeSet)
Back to top
View user's profile Send private message
jeffy2010
Freshman
Freshman


Joined: 18 Nov 2008
Posts: 5

PostPosted: Tue Nov 18, 2008 4:14 pm    Post subject: Reply with quote

Hi MrSnowflake.

I have resolved the issue and the app is running fine now.

The super of SingleWeatherInfoView which was extending the LinearLayout class had a parameter of "Map", which is not available in the LinearLayout.

Removed the Map, and its working fine.

SingleWeatherInfoView.java - line 41
public SingleWeatherInfoView(Context context, AttributeSet attrs,
Map inflateParams) {
super(context, attrs, inflateParams);

Thank you so much.
Back to top
View user's profile Send private message
mlw4428
Once Poster
Once Poster


Joined: 23 Nov 2008
Posts: 1

PostPosted: Sun Nov 23, 2008 11:49 pm    Post subject: Reply with quote

I sorta stumbled across this page and while it sorta doesn't relate to Android development, it is inline with the OP's subject.

I have a library I created (it's open source) that does the similar thing for .NET. If you're interested you can visit my personal site (which I won't give out to keep from making it seem like I' m spamming). You can get it by messaging me or emailing me at mlw4428 at gmail dot com.

And I certainly can feel you on the XML layout..

You can also find it by searching for GWPLNET on sourceforge. But yeah, great article, just wished I found it sooner Razz
Back to top
View user's profile Send private message
stanimir
Freshman
Freshman


Joined: 02 Dec 2008
Posts: 2

PostPosted: Tue Dec 02, 2008 10:45 pm    Post subject: Re: Android Weather Forecast - Google Weather API - Descript Reply with quote

Java:
Button cmd_submit = (Button)findViewById(R.id.cmd_submit);
          cmd_submit.setOnClickListener(new OnClickListener(){
               @Override
               public void onClick(View arg0) {
                    URL url;
                    try {
                         /* Get what user typed to the EditText. */                       
                         String cityParamString =
                              ((EditText)findViewById(R.id.edit_input))
                                   .getText().toString();
                         String queryString =
                              "http://www.google.com/ig/api?weather="
                                   + cityParamString;
                         /* Replace blanks with HTML-Equivalent. */
                         url = new URL(queryString.replace(" ", "%20"));

                         /* Get a SAXParser from the SAXPArserFactory. */
                         SAXParserFactory spf = SAXParserFactory.newInstance();
                         SAXParser sp = spf.newSAXParser();
                         
                         /* Get the XMLReader of the SAXParser we created. */
                         XMLReader xr = sp.getXMLReader();
                         
                         /* Create a new ContentHandler and apply it to the XML-Reader*/
                         GoogleWeatherHandler gwh = new GoogleWeatherHandler();
                         xr.setContentHandler(gwh);
                         
                         /* Parse the xml-data our URL-call returned. */
                         xr.parse(new InputSource(url.openStream()));

                         /* Our Handler now provides the parsed weather-data to us. */
                         WeatherSet ws = gwh.getWeatherSet();
                         
                         /* Update the SingleWeatherInfoView with the parsed data. */
                         updateWeatherInfoView(R.id.weather_today, ws.getWeatherCurrentCondition());
                         
                         updateWeatherInfoView(R.id.weather_1, ws.getWeatherForecastConditions().get(0));
                         updateWeatherInfoView(R.id.weather_2, ws.getWeatherForecastConditions().get(1));
                         updateWeatherInfoView(R.id.weather_3, ws.getWeatherForecastConditions().get(2));
                         updateWeatherInfoView(R.id.weather_4, ws.getWeatherForecastConditions().get(3));
                         
                    } catch (Exception e) {
                         resetWeatherInfoViews();
                         Log.e(DEBUG_TAG, "WeatherQueryError", e);
                    }
               }
          });



I have database with cities from http://www.geonames.org/export/ and use SAX parser in Java Crawler to write in database weather for each city but the SAX parser have encoding problem with weather link like this:
http://www.google.bg/ig/api?weather=Almerķa,ES&hl=en

the xml page is:
XML:
<xml_api_reply version="1">
<weather module_id="0" tab_id="0">
<forecast_information>
<city data="Almeria, AL"/>
<postal_code data="Almerķa,ES"/> <!-- -in this line the SAX parser break -->


I try to fix this with setEncoding to InputSource but the problem exist :)

Java:
java.io.UTFDataFormatException: Invalid byte 2 of 3-byte UTF-8 sequence.
     at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Source)
     at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
     at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
     at org.apache.xerces.impl.XMLEntityScanner.scanLiteral(Unknown Source)
     at org.apache.xerces.impl.XMLScanner.scanAttributeValue(Unknown Source)
     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanAttribute(Unknown Source)
     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
     at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
     at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)



this is my function

Java:
   public void parseDocument(String queryString) {
//queryString = http://www.google.bg/ig/api?weather=Almerķa,ES&hl=en

        //get a factory
        SAXParserFactory spf = SAXParserFactory.newInstance();
        try {
            //get a new instance of parser
            SAXParser sp = spf.newSAXParser();
            // sp.parse(queryString,this);

            URL url = new URL(queryString);
            /* Get the XMLReader of the SAXParser we created. */
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);

            /* Parse the xml-data our URL-call returned. */
            InputSource src = new InputSource(url.openStream());
            src.setEncoding("UTF-8");
            xr.parse(src);
Back to top
View user's profile Send private message
plusminus
Site Admin
Site Admin


Joined: 14 Nov 2007
Posts: 2660
Location: College Park, MD

PostPosted: Tue Dec 02, 2008 11:11 pm    Post subject: Reply with quote

The reason is very probably the "ķ" in the response.

If you search without the thing it works with me:

http://www.google.bg/ig/api?weather=Almeria,ES&hl=en
// instead of
http://www.google.bg/ig/api?weather=Almerķa,ES&hl=en

Best Regards,
Nicolas

_________________
Download my apps Idea
Please remember, that this board is give & take Smile


| Android Development Community / Tutorials
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stanimir
Freshman
Freshman


Joined: 02 Dec 2008
Posts: 2

PostPosted: Wed Dec 03, 2008 9:10 am    Post subject: Reply with quote

This is not the decision of the problem SAX parser do not work with UTF-8..
I don`t have the table with Google name of the city like Almeria and will try to use DOM Parser
Back to top
View user's profile Send private message
AJ Quick
Junior Developer
Junior Developer


Joined: 19 Nov 2008
Posts: 16

PostPosted: Mon Dec 29, 2008 6:17 am    Post subject: Reply with quote

jeffy2010 wrote:
Hi MrSnowflake.

I have resolved the issue and the app is running fine now.

The super of SingleWeatherInfoView which was extending the LinearLayout class had a parameter of "Map", which is not available in the LinearLayout.

Removed the Map, and its working fine.

SingleWeatherInfoView.java - line 41
public SingleWeatherInfoView(Context context, AttributeSet attrs,
Map inflateParams) {
super(context, attrs, inflateParams);

Thank you so much.


I wanted to test this program out.. but I am now having the same error.

Removing Map doesn't fix it the same way it did for you.
Back to top
View user's profile Send private message
weatherdoll
Freshman
Freshman


Joined: 05 Jan 2009
Posts: 2

PostPosted: Wed Jan 07, 2009 2:00 am    Post subject: Thanks for the info Reply with quote

Just wanted to say thanks for providing the info.
It gave me the push needed to start on my own little google weather feed app in Flash
Back to top
View user's profile Send private message
weatherdoll
Freshman
Freshman


Joined: 05 Jan 2009
Posts: 2

PostPosted: Wed Jan 07, 2009 2:04 am    Post subject: Reply with quote

I used PHP as the proxy,
Which loads the xml AND saves a copy of the XML locally on the harddrive to prevent a flood of requests hitting google for the same weather info. It stores the local copy for 1 hour (essentally matching the Yahoo XML feed requirements).

I put most of my code and a current running sample on my website
See:
Googles weather api

Now I will start working on the client interface and get a few versions up.
Back to top
View user's profile Send private message
EverYoung124
Freshman
Freshman


Joined: 08 Dec 2008
Posts: 2

PostPosted: Tue Feb 17, 2009 8:54 pm    Post subject: Reply with quote

plusminus, Thank you very much for the tutorial. It is very helpful. I want to report a problem when I use it on SDK1.1-r1 and provide a solution.

First I used the source code and added the INTERNET use-permission. After installing, an error occurs when I hit the button.
Quote:
E/WeatherForecaster( 419): WeatherQuerryError
E/WeatherForecaster( 419): java.io.FileNotFoundException: http://www.google.com/ig/api?weather=Schriesheim,%20Germany
E/WeatherForecaster( 419): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1040)
E/WeatherForecaster( 419): at java.net.URL.openStream(URL.java:664)


However I can still get the xml file from a browser. After some testing and googling, I find that the program does not like the weather API url and I don't know why it happens. So I switched to HttpClient to open the url. What I did is replace the parse line
Java:
xr.parse(new InputSource(url.openStream()));

with the following
Java:

                     /* Use HTTPClient to deal with the URL */
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpGet httpget = new HttpGet(queryString.replace(" ", "%20"));
                    Log.d(DEBUG_TAG, "executing request " + httpget.getURI());
                    // create a response handler
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                    String responseBody = httpclient.execute(httpget, responseHandler);
                    // Log.d(DEBUG_TAG, "response from httpclient:\n "+responseBody);
                    
                    ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());
                    xr.parse(new InputSource(is));
                    Log.d(DEBUG_TAG, "parse complete");
                    // parse complete


Then the problem goes away. Hope it might help some people.

_________________
Hang on.
Back to top
View user's profile Send private message
marmozsdx
Once Poster
Once Poster


Joined: 15 May 2009
Posts: 1

PostPosted: Fri May 15, 2009 9:42 pm    Post subject: About the Weatherbug API Reply with quote

Hi guys,

I'm new to this site, and I just happen to come across this forum tutorial.

I did find it interesting that there were some issues with the Google API not accepting Lat. and Long., so I did a bit of research on the web and found out about this API from Weatherbug.com. Apparently developers need only register, confirm their account, and they are given a license to use the API.

Their API seems a lot more robust, and it allows for Lat./Long. search, so the GPS functionality can be integrated in a single step.

Here's the link to the API info: http://weather.weatherbug.com/desktop-weather/api.html
and here's a description of the API functionality: http://api.wxbug.net/help.html#compactdescr

I hope it helps you guys. I have not started work on this tutorial, but I will get started and try to implement the Weatherbug API.

Thanks for all the tutorials and the collaboration of all of you.

Francisco
Back to top
View user's profile Send private message
Shalni
Junior Developer
Junior Developer


Joined: 29 Apr 2009
Posts: 17

PostPosted: Thu May 28, 2009 10:11 am    Post subject: Weather Forecasting (1.1 V) Reply with quote

Hi everybody,

Here is the weather forecasting code working on sdk 1.1 as there were some changes to be made inorder to work in 1.1 version from the original code. Hope this helps.

Thank you.



WeatherForecasting.zip
 Description:

Download
 Filename:  WeatherForecasting.zip
 Filesize:  181.36 KB
 Downloaded:  220 Time(s)

Back to top
View user's profile Send private message
armstrong
Once Poster
Once Poster


Joined: 28 Sep 2009
Posts: 1

PostPosted: Wed Sep 30, 2009 8:59 am    Post subject: Reply with quote

I have this problem after entering the xml code into the main.xml.
How can i solve this problem so that my layout will appears ?



notfound.jpg
 Description:
Notfoundexception
 Filesize:  489.07 KB
 Viewed:  2463 Time(s)

notfound.jpg


Back to top
View user's profile Send private message
suman291857
Freshman
Freshman


Joined: 12 Sep 2009
Posts: 2

PostPosted: Mon Nov 09, 2009 4:31 pm    Post subject: Reply with quote

You can infact use google weather API to accept longitude,latitude
Have a look at this post
http://insightmed.eu/blog/2008/programming/web/google-weather-api-php
But i think we have to be carefull abt using google API it as its not official
Thanks for tutorial..It was very usefull...
Back to top
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Advanced Tutorials All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.