×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Using Googel Weather API for weather Info

    Hi,
    I am trying to get the weather info using Google weather API in NOKIA S40 web aap series through javaScript but not able to do this.I am getting the error in follwing line
    var weatherXML = xmlhttp.responseXML
    ;

    error message are,
    Result of expression 'weatherXML' [null] is not an object.

    So kindly help me....

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Googel Weather API for weather Info

    Same code is running finw within the IE browser.

  3. #3
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Using Googel Weather API for weather Info

    Hi,

    You should really as support from Google for this to get definitive answers. I did briefly check this,
    and it appears that they are doing server side magic to detect device used to access Google Weather API.

    Series 40 device is detected as Mobile, thus get (301 moved permanently response) and are redirected to http://www.google.com/m/ig. Where as IE and other desktop browsers do get XML data as usual.

    However the site in http://www.google.com/m/ig no longer offers plain XML, rather they are offering a full mobile optimized site to see the weather.


    Br,
    Ilkka

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Googel Weather API for weather Info

    Hi Ilkka thanks for your reply,
    Here is my complete code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">


    <head>
    <title>Weather Forcasting</title>

    <script type="text/javascript">
    var weather={"onReady":false};

    function IpWeather()
    {
    var xmlhttp=false;


    if (window.ActiveXObject)
    {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    }
    else if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
    xmlhttp = new XMLHttpRequest();
    }

    xmlhttp.open("GET","http://www.google.com/ig/api?weather=bangalore",true);
    // xmlhttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.send();

    xmlhttp.onreadystatechange = function()
    {
    if (xmlhttp.readyState == 4)
    {
    var weatherXML = xmlhttp.responseXML;
    var now = weatherXML.getElementsByTagName("current_conditions")[0];
    var now_t = now.getElementsByTagName('temp_c')[0].getAttribute('data');
    var now_w = now.getElementsByTagName('wind_condition')[0].getAttribute('data');
    var now_c = now.getElementsByTagName('condition')[0].getAttribute('data');
    var now_h = now.getElementsByTagName('humidity')[0].getAttribute('data');

    var today = weatherXML.getElementsByTagName("forecast_conditions")[0];
    var t_max = today.getElementsByTagName('high')[0].getAttribute('data');
    var t_min = today.getElementsByTagName('low')[0].getAttribute('data');
    weather={"t_now":now_t,"wind":now_w,"cloud":now_c,"humidity":now_h,"t_max":t_max,"t_min":t_min,"onReady":true};
    }
    }
    }

    IpWeather();

    </script>
    </head>

    <body>
    <div id='target'></div>
    <script type="text/javascript">
    function weatherInfo()
    {
    if(weather.onReady)
    {
    document.getElementById('target').innerHTML="Weather:"+weather.cloud+" Temperature now:"+weather.t_now+"? whole day between:"+weather.t_min+"--"+weather.t_max+"? "+weather.humidity+" "+weather.wind;
    }
    else
    {
    document.getElementById('target').innerHTML="loading....";
    // setTimeout("weatherInfo()",10);
    }
    }
    weatherInfo();
    </script>
    </body>

    </html>

  5. #5
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Using Googel Weather API for weather Info

    Hi,

    You could implement sanity checks for onreadystatechange function. Something like in code below. However in this case they do not help, as server does not respond in correct format.
    There is nothing that can be done in Web App side to make it work.

    I understood, that Weather API is not targeted to 3rd party developers, so they can change it's functionality without further notice.

    Code:
    xmlhttp.onreadystatechange = function(){
       if (xmlhttp.readyState == 4){
         if (xmlhttp.status== 200){
            if(xmlhttp.responseXML){
               //success!
            }else{
              //handle error
            }
         }else{
            //handle error
         }
      }
    }
    -Ilkka

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Googel Weather API for weather Info

    Hi Ilkka Thanks a lot for your quick reply ,
    I am noy able to detect why i am still getting null in xmlhttp.respomseXml.
    I changed my code bu still getting null at the xmlhttp.responseXML.

    Could you tell me about thsi problem or do you know any alternate way through which i can get the weather info in S40 Web app.

    Thanks in Advance.

  7. #7
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Using Googel Weather API for weather Info

    I would suggest to change Weather API provider.

    Programmable web has a good list to start with:
    http://www.programmableweb.com/apis/...apicat=Weather

    Br,
    Ilkka

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    18

    Re: Using Googel Weather API for weather Info

    Hi Ilkaa,
    And suppose i wish to do this only through google weather API than how can i do this.
    Give me your valuable suggestion in brief because i am new to this technology.

    Thanks in Advance.

  9. #9
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Using Googel Weather API for weather Info

    Hi areefnadaf,

    Unfortunately, using Google weather API is not possible at the moment in Series 40 Web Apps.
    Google uses User Agent string to detect what browser is used to access whether API.
    Desktop browsers do receive correct XML response that has weather data.
    Nokia Browser is redirected to mobile site, that does not have weather data.

    Br,
    Ilkka

Similar Threads

  1. Weather, clock, mail and social Widget improvements
    By silentstormD22 in forum General Development Questions
    Replies: 2
    Last Post: 2012-03-05, 09:20
  2. Replies: 3
    Last Post: 2011-01-07, 09:07
  3. Weather app
    By eronald in forum Python
    Replies: 0
    Last Post: 2006-09-07, 21:22
  4. WAP link for global weather info
    By majeshraj in forum Mobile Web Site Development
    Replies: 0
    Last Post: 2004-02-03, 04:07
  5. Obtaining Local Weather on 9290
    By phoebe66 in forum PersonalJava
    Replies: 0
    Last Post: 2002-08-05, 01:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •