phpxmlgoogle-apigoogle-weather-api

Problem on Google weather report calcuation


This is about the Google Weather Report XML.

What is the calculation Google is doing?

When I google with weather=London,UK keyword, it's showing something like this screen shot,

alt text http://img293.imageshack.us/img293/4746/weathergoogle.jpg

In my XML there is nothing like 26, 11, 26, 22 no

My XML look like below.

alt text

What is the calculation involved in the weather report?

How to get these into PHP variable?


Solution

  • There is no calculation. The XML you linked has these nodes:

    <temp_f data="70"/>
    <temp_c data="21"/>
    

    and

    <low data="11"/>
    <high data="26"/>
    

    The first two are the temperature in Celsius and Fahrenheit for the current weather and corresponds to the left hand part on the Google Seach page. High and Low is what the Google Search Page shows for the Forecast (Celsius only).

    PHP provides a number of libraries for working with XML. The most prominent being DOM, XMLReader and SimpleXML. Have a look at the examples in the PHP Manual on how to use them. Stack Overflow also has numerous questions and answers regarding their usage.


    EDIT after Update: Seems like Google gives you the high/low values in Fahrenheit depending on the language set in the browser requesting the feed. Either add the language param hl=[languagecode] to the URL to see if you can request this in Celsius or - if that's not possible - convert high/low by hand:

                from Fahrenheit               to Fahrenheit
    Celsius     [°C] = ([°F] − 32) × 5⁄9      [°F] = [°C] × 9⁄5 + 32