Welcome to Islandnet.com  
Locally owned and operated since 1993  
Live Help
LOG IN:  Username:    Password:    

Web Gadget: METAR

Description

This gadget provides a PHP function that you can use to retrieve METAR weather information for a given location in the world. It takes care of parsing and interpreting the complex data and uses it to calculate additional information, which is returned to you in an array, making it easy to add current weather data to your sites.

It also provides a global array of the available weather stations and key information about each one.

Usage Summary

@include "gadget:metar";

Details

This gadget provides a global array named $METAR_station_data that has the 4 character station ID code as a key and several fields including 'na' (name), 'st' (state, only for US sites), 'co' (country), 'la' (latitude), 'lo' (longitude), and 'el' (elevation in meters). For example, this code:


@include "gadget:metar";

echo( $METAR_station_data['CYWH']['na'] . '<br>' );
echo( $METAR_station_data['CYWH']['co'] . '<br>' );
echo( $METAR_station_data['CYWH']['la'] . '<br>' );
echo( $METAR_station_data['CYWH']['lo'] . '<br>' );
echo( $METAR_station_data['CYWH']['el'] . '<br>' );

displays the following:







This gadget also provides you with a PHP function named METAR that takes a single parameter: the 4 character weather station ID. It returns an associative array of values including temperature, wind speed and direction, visibility, and much more. For example, the following code:


@include "gadget:metar";

// CWYH is the Victoria Harbour
$data = METAR( 'CYWH' );

while( list( $field, $value ) = each( $data ) )
   echo( "data['{$field}'] = {$value}<br>" );

produces the following output:



Fatal error: Call to undefined function metar() in /usr/home/admin/www/gadgets/metar/index.php on line 78