How to Use Google Weather API in Your Web Page

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)

<strong><em><?php</em></strong><br /> <strong><em> $xml = simplexml_load_file(&#8220;http://www.google.com/ig/api?weather=new-york&#8221;);</em></strong> // get XML file with all data<br /> <strong><em> $current = $xml->xpath(&#8220;/xml_api_reply/weather/current_conditions&#8221;);</em> </strong>// get current temperature and condition<br /> <strong><em> $information = $xml->xpath(&#8220;/xml_api_reply/weather/forecast_information&#8221;);</em> </strong>// get next days temperatures<br /> <strong><em> $forecast_list = $xml->xpath(&#8220;/xml_api_reply/weather/forecast_conditions&#8221;);</em> </strong>// get next days conditions<br /> <strong>?></strong>

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

<strong><em></p> <h1>New-York City Weather</h1> <div class="weather"> <img onload="Wpfcll.r(this,true);" src="https://appsbuilders.org/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif" data-wpfc-original-src="<?php echo ' <a target="_new" rel="nofollow noopener noreferrer" href="http://www.google.com"><div class='code-block code-block-4' style='margin: 8px auto; text-align: center; display: block; clear: both;'> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4295317565354360" data-ad-slot="6145775521" data-ad-format="auto" data-full-width-responsive="true"></ins> <script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></div><div class='code-block code-block-3' style='margin: 8px auto; text-align: center; display: block; clear: both;'> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4295317565354360" data-ad-slot="6145775521" data-ad-format="auto" data-full-width-responsive="true"></ins> <script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></div>http://www.google.com</a> &#8216;.<br /> $current[0]->icon[&#8216;data&#8217;]?>&#8221; alt=&#8221;weather&#8221; /></p> <div class="condition"><strong>Today</strong><br /> <?php echo $current[0]->temp_f[&#8216;data&#8217;]?>° F,<?php echo $current[0]->condition[&#8216;data&#8217;]?></div></p></div><p> <?php foreach ($forecast_list as $forecast) {?></p> <div class="weather"> <img onload="Wpfcll.r(this,true);" src="https://appsbuilders.org/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif" data-wpfc-original-src="<?php echo ' <a target="_new" rel="nofollow noopener noreferrer" href="http://www.google.com">http://www.google.com</a> &#8216;.<br /> $forecast->icon[&#8216;data&#8217;]?>&#8221; alt=&#8221;weather&#8221; /></p> <div class="condition"> <strong><?php echo $forecast->day_of_week[&#8216;data&#8217;];?></strong><br /> <?php echo $forecast->low[&#8216;data&#8217;]?>° F &#8211; <?php echo $forecast->high[&#8216;data&#8217;]?>° F,<br /> <?php echo $forecast->condition[&#8216;data&#8217;]?></div><div class="wp_random_inside"><span class="dashicons dashicons-awards"></span><a href="https://appsbuilders.org/guides/creating-realtime-apps-with-angular-2-and-meteor-uri-goldshtein/">Creating realtime apps with Angular 2 and Meteor &#8211; Uri Goldshtein</a></div></div><p> <?php }?></em></strong>

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

<strong><em></p> <style></em></strong> <strong><em>.weather{width:245px;height:40px;background:#d7d7d7;padding:2px;margin-bottom:2px;} .weather img{float:left;} .weather.condition{width:200px;height:40px;float:right;text-align:left;}</em></strong> <strong><em></style> <p></em></strong>


Related Posts
Want to Learn How to Make Your Own Website?

For those who have an online business, it is imperative to have a website. You cannot expand you business Read more

Resolving Error 0x80040609 Steps

Windows live is the most popular web service provided by Microsoft. This service will help you to stay connected Read more

Resolving Customer Complaints and Conflict with the L-E-A-R-N Technique

Handling customer complaints is an important part of keeping your business healthy and profitable. If you want your customers Read more

Advantages and Disadvantages of Customized Software

Other questions you could ask: Advantages and disadvantages of proprietary software what is proprietary software? How to customise fields Read more

Leave a Comment