PHP Classes

File: demo_PlusCodeLocal.php

Recommend this page to a friend!
  Classes of Ray Paseur   PHP PlusCode Local   demo_PlusCodeLocal.php   Download  
File: demo_PlusCodeLocal.php
Role: Example script
Content type: text/plain
Description: Demonstration Script
Class: PHP PlusCode Local
Get the location information from PlusCode
Author: By
Last change: Added additional links to the demonstrations
Date: 5 years ago
Size: 2,401 bytes
 

Contents

Class file image Download
<?php // demo_PlusCodeLocal.php
/**
 * Documentation References:
 *
 * https://www.geonames.org/about.html
 * https://www.geonames.org/export/ws-overview.html
 * https://www.geonames.org/export/web-services.html#findNearby
 * https://www.geonames.org/export/codes.html
 */
error_reporting(E_ALL);

// DEPENDENCY!
// You must get your own api key from GeoNames.org
require_once('class_PlusCode.php');
require_once(
'class_PlusCodeLocal.php'); // <-- API Key goes in this script

echo '<pre>';


// A collection of curated examples
$latlng = array
(
'Google Earth default USA center in LAWRENCE, KANSAS' => ' 38.95939, -95.2654831'
, 'Washington Monument' => ' 38.8894838, -77.0352791'
, 'Post Office 15213 in Pittsburgh' => ' 40.4401766, -79.9526167'
, 'Ivy City Smokehouse in DC' => ' 38.9146348, -76.9855517'
, 'Seatac Airport, according to Google' => ' 47.4502535, -122.3110052'
, 'Eiffel Tower, Paris' => ' 48.8583701, 2.2944813'
, 'Sydney Opera House' => '-33.8567844, 151.2152966'
, 'Obelisco de Buenos Aires' => '-34.6037389, -58.3815703'
, 'Merlion, Marina Bay, Singapore' => ' 1.286833, 103.8545280'
, 'La Basilica del Voto Nacional, Quito, Ecuador' => ' -0.2144375, -78.5071875'
, 'Mu Pagoa Waterfall, Puleia Samoa' => '-13.7768121, -172.3786318'
, 'The Taj Mahal' => ' 27.1750151, 78.0421552'
)
;

// Process each of the examples
foreach ($latlng as $name => $spot) {
   
sleep(1);
   
$plus = PlusCode::geocode_to_olc($spot);
   
$local = PlusCodeLocal::get($plus);
   
$ulocal = urlencode($local);

    echo
PHP_EOL;
    echo
PHP_EOL . "<b>$name</b>";
    echo
PHP_EOL . 'Input Lat,Lng: <a target="_blank" href="https://www.google.com/maps?q=' . $spot . '">' . $spot . '</a>';
    echo
PHP_EOL . 'Computed PlusCode: <a target="_blank" href="https://plus.codes/' . $plus . '">' . $plus . '</a>';
    echo
PHP_EOL . 'Localized PlusCode: <a target="_blank" href="https://plus.codes/' . $ulocal . '">' . $local . '</a> via Plus.Codes/';
    echo
PHP_EOL . 'Localized PlusCode: <a target="_blank" href="https://www.google.com/maps?q=' . $ulocal . '">' . $local . '</a> via Google/Maps';
    echo
PHP_EOL;

}