c3t4r4/openlocationcode
最新稳定版本:v1.1.1
Composer 安装命令:
composer require c3t4r4/openlocationcode
包简介
Open Location Code (Plus Codes) implementation for PHP - Convert locations to and from short codes - Forked from google/open-location-code
README 文档
README
A PHP implementation of Open Location Code (also known as Plus Codes).
Open Location Code is a technology that provides a way to encode location into a form that is easier to use than latitude and longitude. The codes generated are called Plus Codes.
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
composer require c3t4r4/openlocationcode
Basic Usage
Encode a location
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
Decode a code
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();
Shorten a code
use OpenLocationCode\OpenLocationCode; $shortCode = OpenLocationCode::shorten('8FVC9G8F+6X', 47.5, 8.5); echo $shortCode; // 9G8F+6X
Recover a full code
use OpenLocationCode\OpenLocationCode; $fullCode = OpenLocationCode::recoverNearest('9G8F+6X', 47.4, 8.6); echo $fullCode; // 8FVC9G8F+6X
Testing
This project uses Pest PHP for testing:
# Run all tests with Pest (recommended) composer test # Run with PHPUnit (legacy support) composer test:phpunit # Run specific test file ./vendor/bin/pest tests/BasicTest.pest.php
Test Status: ✅ 782/796 tests passing (98.2%)
- All critical functionality tested and working
- Round-trip encoding/decoding: 100% functional
- Minor variations in 14 edge cases are mathematically acceptable
Documentation
- API Documentation - Complete API reference
- Quick Start Guide - Step-by-step tutorial
- Test Status - Detailed test analysis
- Pest Migration - Testing framework guide
- Portuguese README - Documentação em Português
For the official specification, visit the Open Location Code repository.
License
Copyright 2024 Google Inc.
Licensed under the Apache License, Version 2.0.
统计信息
- 总下载量: 131
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-10-16