| 
<?php // classes/demo_Geocode.php/**
 * Class Geocode Demonstration Script
 */
 error_reporting(E_ALL);
 
 // Load the Class
 require_once('class_Geocode.php');
 
 // Make sure that php works with UTF-8
 mb_internal_encoding('utf-8');
 mb_regex_encoding('utf-8');
 mb_http_output('utf-8');
 
 
 // Test Objects
 Class TO
 {
 public $name, $geo;
 public function __construct($name, $geo) {
 $this->name = $name;
 $this->geo  = $geo;
 }
 }
 
 
 // A collection of curated examples, giving Geocode information in widely varying formats
 $testdata=[];
 
 // GOOD examples
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40.4401766,-79.9526167' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40.4401766°N,79.9526167°W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26.4106\'N,79°57.157\'W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26\'24.636"N,79°57\'9.42"W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26'24.636"N,79°57'9.42"W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26′24.636″N,79°57′9.42″W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26’24.636”N,79°57‘9.42“W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '40°26’24.636“N,79°57’9.42“W' );
 $testdata[] = new TO( 'Post Office 15213 in Pittsburgh', '87G2C2RW+3X' );
 
 $testdata[] = new TO( 'Seatac Airport (Google data)', '47° 26.59′ -122° 18.42′' );
 $testdata[] = new TO( 'Seatac Airport (Google data)', '47.443167, -122.307' );
 $testdata[] = new TO( 'Seatac Airport (TFlite data)', 'N47 26.59 W122 18.42' );
 
 $testdata[] = new TO( 'Sydney Opera House', '-33.8567844,151.2152966' );
 $testdata[] = new TO( 'Sydney Opera House', '33°51′24.4″S 151°12\'55.1"E' );
 
 $testdata[] = new TO( 'The Taj Mahal', ' 27.1750151,   78.0421552' );
 $testdata[] = new TO( 'The Taj Mahal', '27 ° 10\'30.05 "North and 78 ° 2\'31.76" East' );
 $testdata[] = new TO( 'The Taj Mahal', '27.1750154 78.042155');
 $testdata[] = new TO( 'The Taj Mahal', '7JVW52GR+2V');
 
 // BAD examples
 $testdata[] = new TO( 'Malformed LNG', 'Lat N48 42.29, Long W122.54.40' );  //   Note two decimal points, a not-well-formed number
 $testdata[] = new TO( 'Impossible LAT', '138.9304,-77.1481' );
 $testdata[] = new TO( 'Impossible LNG', '38.9304,-277.1481' );
 $testdata[] = new TO( 'Impossible LAT,LNG', '138.9304,-277.1481' );
 $testdata[] = new TO( 'Coordinates not Geocode or OLC', '0' );
 $testdata[] = new TO( 'Coordinates missing', '' );
 $testdata[] = new TO( 'Coordinates goofy', 'gooseball' );
 
 
 // Process each of the examples
 echo '<meta charset="utf-8" />';
 echo '<pre>';
 foreach ($testdata as $to)
 {
 echo "<h3>$to->name: " . '<a target="_blank" href="https://www.google.com/maps?q=' . urlencode($to->geo) . '">' . $to->geo . '</a> </h3>';
 $geothing = new Geocode($to->geo, $to->name);
 if (empty($geothing->error)) {
 print_r($geothing);
 echo '<a target="_blank" href="https://www.google.com/search?q=' . urlencode($geothing->geo)        . '">' . $geothing->geo     . '</a> computed geocode in D.ddd decimal' . PHP_EOL;
 echo '<a target="_blank" href="https://www.google.com/search?q=' . urlencode($geothing->geo_dd)     . '">' . $geothing->geo_dd  . '</a> computed geocode in D.ddd° decimal degrees' . PHP_EOL;
 echo '<a target="_blank" href="https://www.google.com/search?q=' . urlencode($geothing->geo_dmd)    . '">' . $geothing->geo_dmd . '</a> computed geocode in D°M.mmm\' degrees decimal minutes' . PHP_EOL;
 echo '<a target="_blank" href="https://www.google.com/search?q=' . urlencode($geothing->geo_dms)    . '">' . $geothing->geo_dms . '</a> computed geocode in D°M\'S.sss" degrees minutes decimal seconds' . PHP_EOL;
 echo '<a target="_blank" href="https://plus.codes/'              . urlencode($geothing->olc)        . '">' . $geothing->olc     . '</a> open location code link on plus.codes' . PHP_EOL;
 }
 else {
 echo $geothing->error . PHP_EOL;
 }
 echo PHP_EOL;
 }
 
 |