There are many reasons to add Weather API to your website. 124,000,000 search queries for “Weather” are processed each month, and sometimes it relates to your business. How can you add it? How to find the one that will fit your desired area? Is there a free tool online to build it?
The answer for all this questions is Google’s Weather API. Google has an API that processed information about Weather temperatures and conditions for 5 days, the recent and 4 days forward. Like all others API that Google developed, it’s free.
Basically you need to be knowledgeable with HTML, CSS and PHP. The code contains the information puller (PHP), and the designer code (HTML & CSS).
The PHP part (this part will be added before the next HTML/PHP code)
$xml = simplexml_load_file(“http://www.google.com/ig/api?weather=new-york”); // get XML file with all data
$current = $xml->xpath(“/xml_api_reply/weather/current_conditions”); // get current temperature and condition
$information = $xml->xpath(“/xml_api_reply/weather/forecast_information”); // get next days temperatures
$forecast_list = $xml->xpath(“/xml_api_reply/weather/forecast_conditions”); // get next days conditions
This will pull all the information about the place you chose, and will be ready to be placed inside your page with PHP code.
The HTML & PHP part
New-York City Weather
$current->icon[‘data’]?>” alt=”weather” />
$forecast->icon[‘data’]?>” alt=”weather” />
low[‘data’]?>° F – high[‘data’]?>° F,
This part place your data together with its own design. It is important to design it, since you will want to place it in a particular spot on the page, and to use your website color. Next you will find CSS code that I have used to create simple table of weather.
The CSS part