PHP Classes

File: demo_PlusCode.php

Recommend this page to a friend!
  Classes of Ray Paseur   PHP PlusCode   demo_PlusCode.php   Download  
File: demo_PlusCode.php
Role: Example script
Content type: text/plain
Description: PlusCode Demo
Class: PHP PlusCode
Generate PlusCode parameters for Google Maps links
Author: By
Last change:
Date: 5 years ago
Size: 2,379 bytes
 

Contents

Class file image Download
<?php // classes/demo_PlusCode.php
/**
 * Demonstrate how to use the PlusCode Static Class
 *
 * Refs:
 * https://en.wikipedia.org/wiki/Open_Location_Code
 * https://github.com/google/open-location-code/blob/master/docs/olc_definition.adoc
 * https://github.com/google/open-location-code/blob/master/docs/olc_definition.adoc#open-location-code-specification
 *
 * Latitude Distance from the Equator
 * 90 N == 90 North Pole
 * 90 S == -90 South Pole
 *
 * Longitude Distance from Prime Meridian (Greenwich)
 * 180 W == -180
 * 180 E == 180
 * 180º from Greenwich in either direction is "antimeridian" (International Date Line)
 */
error_reporting(E_ALL);
require_once(
'class_PlusCode.php');
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'
)
;


// PROCESS EACH OF THE EXAMPLES
foreach ($latlng as $name => $spot)
{
   
$olc = PlusCode::geocode_to_olc($spot);
   
$llo = PlusCode::olc_to_geocode($olc);

    echo
PHP_EOL . "<b>$name</b>";
    echo
PHP_EOL . 'Input Geocode Lat,Lng: <a target="_blank" href="https://www.google.com/maps?q=' . $spot . '">' . $spot . '</a>';
    echo
PHP_EOL . 'Computed OLC PlusCode: <a target="_blank" href="https://www.google.com/maps?q=' . urlencode($olc) . '">' . $olc . '</a>';
    echo
PHP_EOL . 'Lat,Lng from PlusCode: <a target="_blank" href="https://www.google.com/maps?q=' . $llo . '">' . $llo . '</a>';
    echo
PHP_EOL;
}