You are here:  » Google Weather API


Google Weather API

Submitted by russellharrower on Tue, 2009-05-05 16:31 in

Hi guys having a bit of an issue with google API weather app

This is the code i am using

<?php
$q = @$_GET['q'];
print $q;
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    print_r($record);
    // The following code will print out each field in your sample data:
    print $record["XML_API_REPLY"];
   print $record["FORECAST_CONDITIONS"];
echo "<br/>";
    print $record["DAY_OF_WEEK"];
echo "<br/>";
    print $record["DAY_OF_WEEK-DATA"];
echo "<br/>";
    print $record["LOW"];
echo "<br/>";
    print $record["LOW-DATA"];
echo "<br/>";
    print $record["HIGH"];
echo "<br/>";
    print $record["HIGH-DATA"];
echo "<br/>";
    print $record["ICON"];
echo "<br/>";
    print $record["ICON-DATA"];
echo "<br/>";
    print $record["CONDITION"];
echo "<br/>";
    print $record["CONDITION-DATA"];
  }
  $url = "www.google.com/ig/api?weather=".$q."";
  MagicParser_parse("http://".$url,"myRecordHandler","xml|XML_API_REPLY/WEATHER/FORECAST_CONDITIONS/");
?>

However this is what it is printing out

Perth, AustraliaArray ( [FORECAST_CONDITIONS] => [DAY_OF_WEEK] => [DAY_OF_WEEK-DATA] => Wed [LOW] => [LOW-DATA] => 54 [HIGH] => [HIGH-DATA] => 79 [ICON] => [ICON-DATA] => /ig/images/weather/sunny.png [CONDITION] => [CONDITION-DATA] => Sunny )
Wed
54
79
/ig/images/weather/sunny.png
SunnyArray ( [FORECAST_CONDITIONS] => [DAY_OF_WEEK] => [DAY_OF_WEEK-DATA] => Thu [LOW] => [LOW-DATA] => 53 [HIGH] => [HIGH-DATA] => 79 [ICON] => [ICON-DATA] => /ig/images/weather/sunny.png [CONDITION] => [CONDITION-DATA] => Sunny )
Thu
53
79
/ig/images/weather/sunny.png
SunnyArray ( [FORECAST_CONDITIONS] => [DAY_OF_WEEK] => [DAY_OF_WEEK-DATA] => Fri [LOW] => [LOW-DATA] => 52 [HIGH] => [HIGH-DATA] => 77 [ICON] => [ICON-DATA] => /ig/images/weather/sunny.png [CONDITION] => [CONDITION-DATA] => Sunny )
Fri
52
77
/ig/images/weather/sunny.png
SunnyArray ( [FORECAST_CONDITIONS] => [DAY_OF_WEEK] => [DAY_OF_WEEK-DATA] => Sat [LOW] => [LOW-DATA] => 52 [HIGH] => [HIGH-DATA] => 77 [ICON] => [ICON-DATA] => /ig/images/weather/partly_cloudy.png [CONDITION] => [CONDITION-DATA] => Partly Cloudy )
Sat
52
77
/ig/images/weather/partly_cloudy.png
Partly Cloudy

Submitted by support on Tue, 2009-05-05 18:43

Hi Russell,

Could you perhaps describe what output format you are looking for and I'll suggest what code to use within your myRecordHandler function...

It does appear to be parsing correctly, so it's just down to making sense of the data in the record handler function in the format you require...

Cheers!
David.