{"id":22900325,"url":"https://github.com/vectorial1024/open-location-code-php","last_synced_at":"2025-05-08T01:12:13.455Z","repository":{"id":257807271,"uuid":"860854765","full_name":"Vectorial1024/open-location-code-php","owner":"Vectorial1024","description":"A modern PHP implementation of Open Location Code","archived":false,"fork":false,"pushed_at":"2024-11-13T07:37:59.000Z","size":163,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T01:12:00.292Z","etag":null,"topics":["geo","gps","openlocationcode","php","pluscode"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/vectorial1024/open-location-code-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vectorial1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-21T10:50:10.000Z","updated_at":"2025-04-19T22:38:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"397a2137-f8fd-4fe5-83f3-e5d03c724411","html_url":"https://github.com/Vectorial1024/open-location-code-php","commit_stats":null,"previous_names":["vectorial1024/open-location-code-php"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Fopen-location-code-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Fopen-location-code-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Fopen-location-code-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vectorial1024%2Fopen-location-code-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vectorial1024","download_url":"https://codeload.github.com/Vectorial1024/open-location-code-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978779,"owners_count":21834917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geo","gps","openlocationcode","php","pluscode"],"created_at":"2024-12-14T01:19:01.485Z","updated_at":"2025-05-08T01:12:13.431Z","avatar_url":"https://github.com/Vectorial1024.png","language":"PHP","readme":"# open-location-code-php\n[![Packagist License][packagist-license-image]][packagist-url]\n[![Packagist Version][packagist-version-image]][packagist-url]\n[![Packagist Downloads][packagist-downloads-image]][packagist-stats-url]\n[![PHP Dependency Version][php-version-image]][packagist-url]\n[![GitHub Actions Workflow Status][php-build-status-image]][github-actions-url]\n[![GitHub Repo Stars][github-stars-image]][github-repo-url]\n\nThis is a modern PHP port of the `google/open-location-code` repository. Please visit https://github.com/google/open-location-code for discussion and up-to-date information about **Open Location Code (\"OLC\", aka \"Plus Code\")** itself. This repository only concerns the PHP implementation.\n\nBut still, a short quote from said repository to introduce Open Location Code (OLC):\n\n\u003e Open Location Code is a technology that gives a way of encoding location into a form that is easier to use than latitude and longitude. The codes generated are called plus codes, as their distinguishing attribute is that they include a \"+\" character.\n\nAn [external demo](https://plus.codes/map) is available to showcase the functionality of Open Lcation Code.\n\n## Implementation notes\nThis PHP implementation is adapted from the [Java implementation](https://github.com/google/open-location-code/tree/main/java) of `google/open-location-code`.\n\nThis implementation tries to use latest PHP features where possible.\n\nLicence follows `google/open-location-code`.\n\n## Installation\nvia Composer:\n\n```sh\ncomposer require vectorial1024/open-location-code-php\n```\n\n**Special Notice**: to ensure 32-bit PHP compatibility, this library will check the PHP runtime and, if it detects a 32-bit PHP runtime, will use `float` variables instead of `int` variables to calculate Open Location Codes.\nThis may cause some unintended inaccuracies in 32-bit PHP, but generally speaking, there should be no problems.\n\n## Example code\n\n### Checking and creating OLC codes\n\n```php\nuse Vectorial1024\\OpenLocationCodePhp\\OpenLocationCode;\n\n// This code snippet will center around King's Cross station in London, UK.\n// Its main entrance at (51.530812, -0.123767) has the Open Location Code of \"9C3XGVJG+8F\".\n\n$invalidCode = \"11iL!Illi1!!!\";\n\n$kingsCrossLatitude = 51.530812;\n$kingsCrossLongitude = -0.123767;\n$kingsCrossCode = \"9C3XGVJG+8F\";\n\n// test validity of the code\n$validity = OpenLocationCode::isValidCode($invalidCode); // invalid code; returns false\n$validity = OpenLocationCode::isValidCode($kingsCrossCode); // valid code; returns true\n\n// create object from code\n$invalidObject = OpenLocationCode::createFromCode($invalidCode); // invalid code; throws InvalidArgumentException\n$validObject = OpenLocationCode::createFromCode($kingsCrossCode); // returns OpenLocationCode instance\n// alternatively, create object from coordinates\n$anotherValidObject = OpenLocationCode::createFromCoordinates($kingsCrossLatitude, $kingsCrossLongitude); // returns OpenLocationCode instance\n\n// you may check the code is valid\n$validity = $validObject-\u003eisValid(); // returns true\n$validity = $anotherValidObject-\u003eisValid(); // also returns true\n// you may also read the code...\nassert($kingsCrossCode == $validObject-\u003ecode); // passes\n$code = (string) $validObject; // also, can be explicitly casted to string\nassert($kingsCrossCode == $code); // passes\n// ...to know that both methods result in the same code\nassert($validObject-\u003ecode == $anotherValidObject-\u003ecode); // also passes\n// but you may not modify the code (create a new instance instead!)\n$validObject-\u003ecode = \"something else\"; // PHP runtime error: $code is read-only\n```\n\n### Other references\n\nA quick reference of available classes/methods; please see the PHPDoc for details.\n\n**OpenLocationCode**:\n\n```php\n/* Vectorial1024\\OpenLocationCodePhp\\OpenLocationCode */\n\nclass OpenLocationCode implements Stringable\n{\n    public readonly string $code;\n    // The explicit string cast gives $this-\u003ecode;\n\n    public const int CODE_PRECISION_NORMAL = 10;\n    \n    public static function createFromCode(string $code): self;\n    public static function createFromCoordinates(float $latitude, float $longitude, int $codeLength = self::CODE_PRECISION_NORMAL): self;\n    public static function encode(float $latitude, float $longitude, int $codeLength = self::CODE_PRECISION_NORMAL): string;\n    public function decode(): Vectorial1024\\OpenLocationCodePhp\\CodeArea;\n\n    public function shorten(float $referenceLatitude, float $referenceLongitude): self;\n    public function recover(float $referenceLatitude, float $referenceLongitude): self;\n\n    public function contains(float $latitude, float $longitude): bool;\n    // note: if you need to call contains() many times on the same $this, consider decoding $this first, and then call contains() on the resulting CodeArea instance\n\n    public static function isValidCode(string $code): bool;\n    public function isValid(): bool;\n    public function isFull(): bool;\n    public function isShort(): bool;\n    public function isPadded(): bool;\n}\n```\n\n**CodeArea**:\n\n```php\n/* Vectorial1024\\OpenLocationCodePhp\\CodeArea */\n\nclass CodeArea\n{\n    public readonly float $southLatitude;\n    public readonly float $westLongitude;\n    public readonly float $northLatitude;\n    public readonly float $eastLongitude;\n    public readonly int $length;\n\n    public function getLatitudeHeight(): float;\n    public function getLongitudeWidth(): float;\n\n    public function getCenterLatitude(): float;\n    public function getCenterLongitude(): float;\n\n    public function contains(float $latitude, float $longitude): bool;\n}\n```\n\n## Testing\nPHPUnit via Composer:\n\n```sh\ncomposer run-script test\n```\n\n[packagist-url]: https://packagist.org/packages/vectorial1024/open-location-code-php\n[packagist-stats-url]: https://packagist.org/packages/vectorial1024/open-location-code-php/stats\n[github-repo-url]: https://github.com/Vectorial1024/open-location-code-php\n[github-actions-url]: https://github.com/Vectorial1024/open-location-code-php/actions/workflows/php.yml\n\n[packagist-license-image]: https://img.shields.io/packagist/l/vectorial1024/open-location-code-php?style=plastic\n[packagist-version-image]: https://img.shields.io/packagist/v/vectorial1024/open-location-code-php?style=plastic\n[packagist-downloads-image]: https://img.shields.io/packagist/dm/vectorial1024/open-location-code-php?style=plastic\n[php-version-image]: https://img.shields.io/packagist/dependency-v/vectorial1024/open-location-code-php/php?style=plastic\u0026label=PHP\n[php-build-status-image]: https://img.shields.io/github/actions/workflow/status/Vectorial1024/open-location-code-php/php.yml?style=plastic\n[github-stars-image]: https://img.shields.io/github/stars/vectorial1024/open-location-code-php\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorial1024%2Fopen-location-code-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvectorial1024%2Fopen-location-code-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorial1024%2Fopen-location-code-php/lists"}