<?php
/*************************************************************
 * This block of code is here to enable source display.
 * This is because this is demonstration code.
 * This would normally never be included in production code.
 */

if (isset($_REQUEST['show_source'])) {
    
show_source(__FILE__);
    exit ;
}

/*************************************************************
 */

/**
 * Three params should be passed to this API as GET parameters.
 *
 * @param string $_REQUEST['origin']
 * The starting location. This should be a
 * free form address or location that contains
 * enough information for Google to unambiguously
 * determine the location.
 *
 * @param string $_REQUEST['destination']
 * The destination location. This should be a
 * free form address or location that contains
 * enough information for Google to unambiguously
 * determine the location.
 *
 * @param string $_REQUEST['mode']
 * This should contain one of four values.
 *      Driving
 *      Walking
 *      Bicycling
 *      Transit
 *
 * @return string
 * Text (with possible HTML markup) giving the direction
 * from origin to destination or, if an error occured,
 * an error message.
 */

include 'class/map.php';
$map = new mapClass;
$directions $map -> directions($_REQUEST['origin'], $_REQUEST['destination'], $_REQUEST['mode']);
$directions json_decode($directionstrue);
if (
$directions["status"] == "OK") {
    
/* Google returns a large JSON object with much information,
     * so we have to extract the text directions.
     */
    
foreach ($directions['routes'][0]['legs'][0]['steps'] as $step) {
        
$step str_ireplace('<br>'''$step['html_instructions']) . '<br><br>';
        
$step str_ireplace('</div><br>''</div>'$step);
        echo 
$step;
    }
} else {
    echo 
$directions["status"];
}