PHP code example of c3t4r4 / openlocationcode
1. Go to this page and download the library: Download c3t4r4/openlocationcode library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
c3t4r4 / openlocationcode example snippets
use OpenLocationCode\OpenLocationCode;
// Encode with default precision (10 characters = ~13.5x13.5 meters)
$code = OpenLocationCode::encode(47.365590, 8.524997);
echo $code; // 8FVC9G8F+6X
// Encode with custom precision (11 characters = ~2.8x3.5 meters)
$code = OpenLocationCode::encode(47.365590, 8.524997, 11);
echo $code; // 8FVC9G8F+6XQ
use OpenLocationCode\OpenLocationCode;
$codeArea = OpenLocationCode::decode('8FVC9G8F+6X');
echo "Latitude Center: " . $codeArea->latitudeCenter . "\n";
echo "Longitude Center: " . $codeArea->longitudeCenter . "\n";
echo "Code Length: " . $codeArea->codeLength . "\n";
// Get center coordinates as array
[$lat, $lng] = $codeArea->getLatLng();
use OpenLocationCode\OpenLocationCode;
$shortCode = OpenLocationCode::shorten('8FVC9G8F+6X', 47.5, 8.5);
echo $shortCode; // 9G8F+6X
use OpenLocationCode\OpenLocationCode;
$fullCode = OpenLocationCode::recoverNearest('9G8F+6X', 47.4, 8.6);
echo $fullCode; // 8FVC9G8F+6X