PHPackages                             vectorial1024/open-location-code-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vectorial1024/open-location-code-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vectorial1024/open-location-code-php
====================================

Open Location Code (aka "Plus Code") implemented in PHP

1.1.4(1mo ago)161.6k↑657.1%Apache-2.0PHPPHP ^8.3CI passing

Since Oct 3Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/Vectorial1024/open-location-code-php)[ Packagist](https://packagist.org/packages/vectorial1024/open-location-code-php)[ GitHub Sponsors](https://github.com/Vectorial1024)[ RSS](/packages/vectorial1024-open-location-code-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

open-location-code-php
======================

[](#open-location-code-php)

[![Packagist License](https://camo.githubusercontent.com/287d6ef6a041ba0b832abd06d9ac345f298177437f714dbf9fe952373cd0e8cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f766563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d7068703f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/open-location-code-php)[![Packagist Version](https://camo.githubusercontent.com/92070ae8aa7f23886ce5d4c90b791545f41e1f9e115766544cbd7cc22d567722/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d7068703f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/open-location-code-php)[![Packagist Downloads](https://camo.githubusercontent.com/aaee503bc91ec45a16729e81ddb49163f7dbc37a4ca2a81b5f862041fdafafa8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f766563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d7068703f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/open-location-code-php/stats)[![PHP Dependency Version](https://camo.githubusercontent.com/ea3486ab381fc474289d990064843fdb4c873190daf046a73922d2d60a015219/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f766563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d7068702f7068703f7374796c653d706c6173746963266c6162656c3d504850)](https://packagist.org/packages/vectorial1024/open-location-code-php)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/9df1da210385bea9c60ffaf5169c50d12515e1341e433c5393bb9f697ea70531/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d7068702f7068702e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/open-location-code-php/actions/workflows/php.yml)[![GitHub Repo Stars](https://camo.githubusercontent.com/9091400897300e3dbaa2d9a9b5261516d443dd216ed8afa63604bb17705fabc1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f766563746f7269616c313032342f6f70656e2d6c6f636174696f6e2d636f64652d706870)](https://github.com/Vectorial1024/open-location-code-php)[![GitHub Sponsors](https://camo.githubusercontent.com/2b86cdb303c515ccf3e1f9f6e6f5a0c4da487ffd74afa6560cbf4b2391ca7610/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f566563746f7269616c313032343f7374796c653d706c6173746963)](https://github.com/sponsors/Vectorial1024)

This is a modern PHP port of the `google/open-location-code` repository. Please visit  for discussion and up-to-date information about **Open Location Code ("OLC", aka "Plus Code")** itself. This repository only concerns the PHP implementation.

But still, a short quote from said repository to introduce Open Location Code (OLC):

> 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.

An [external demo](https://plus.codes/map) is available to showcase the functionality of Open Lcation Code.

Implementation notes
--------------------

[](#implementation-notes)

This PHP implementation is adapted from the [Java implementation](https://github.com/google/open-location-code/tree/main/java) of `google/open-location-code`.

This implementation tries to use latest PHP features where possible.

Licence follows `google/open-location-code`.

Installation
------------

[](#installation)

via Composer:

```
composer require vectorial1024/open-location-code-php
```

**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. This may cause some unintended inaccuracies in 32-bit PHP, but generally speaking, there should be no problems.

### Change log

[](#change-log)

Please see `CHANGELOG.md`.

Example code
------------

[](#example-code)

### Checking and creating OLC codes

[](#checking-and-creating-olc-codes)

```
use Vectorial1024\OpenLocationCodePhp\OpenLocationCode;

// This code snippet will center around King's Cross station in London, UK.
// Its main entrance at (51.530812, -0.123767) has the Open Location Code of "9C3XGVJG+8F".

$invalidCode = "11iL!Illi1!!!";

$kingsCrossLatitude = 51.530812;
$kingsCrossLongitude = -0.123767;
$kingsCrossCode = "9C3XGVJG+8F";

// test validity of the code
$validity = OpenLocationCode::isValidCode($invalidCode); // invalid code; returns false
$validity = OpenLocationCode::isValidCode($kingsCrossCode); // valid code; returns true

// create object from code
$invalidObject = OpenLocationCode::createFromCode($invalidCode); // invalid code; throws InvalidArgumentException
$validObject = OpenLocationCode::createFromCode($kingsCrossCode); // returns OpenLocationCode instance
// alternatively, create object from coordinates
$anotherValidObject = OpenLocationCode::createFromCoordinates($kingsCrossLatitude, $kingsCrossLongitude); // returns OpenLocationCode instance

// you may check the code is valid
$validity = $validObject->isValid(); // returns true
$validity = $anotherValidObject->isValid(); // also returns true
// you may also read the code...
assert($kingsCrossCode == $validObject->code); // passes
$code = (string) $validObject; // also, can be explicitly casted to string
assert($kingsCrossCode == $code); // passes
// ...to know that both methods result in the same code
assert($validObject->code == $anotherValidObject->code); // also passes
// but you may not modify the code (create a new instance instead!)
$validObject->code = "something else"; // PHP runtime error: $code is read-only
```

### Other references

[](#other-references)

A quick reference of available classes/methods; please see the PHPDoc for details.

**OpenLocationCode**:

```
/* Vectorial1024\OpenLocationCodePhp\OpenLocationCode */

class OpenLocationCode implements Stringable
{
    public readonly string $code;
    // The explicit string cast gives $this->code;

    public const int CODE_PRECISION_NORMAL = 10;

    public static function createFromCode(string $code): self;
    public static function createFromCoordinates(float $latitude, float $longitude, int $codeLength = self::CODE_PRECISION_NORMAL): self;
    public static function encode(float $latitude, float $longitude, int $codeLength = self::CODE_PRECISION_NORMAL): string;
    public function decode(): Vectorial1024\OpenLocationCodePhp\CodeArea;

    public function shorten(float $referenceLatitude, float $referenceLongitude): self;
    public function recover(float $referenceLatitude, float $referenceLongitude): self;

    public function contains(float $latitude, float $longitude): bool;
    // 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

    public static function isValidCode(string $code): bool;
    public function isValid(): bool;
    public function isFull(): bool;
    public function isShort(): bool;
    public function isPadded(): bool;
}
```

**CodeArea**:

```
/* Vectorial1024\OpenLocationCodePhp\CodeArea */

class CodeArea
{
    public readonly float $southLatitude;
    public readonly float $westLongitude;
    public readonly float $northLatitude;
    public readonly float $eastLongitude;
    public readonly int $length;

    public function getLatitudeHeight(): float;
    public function getLongitudeWidth(): float;

    public function getCenterLatitude(): float;
    public function getCenterLongitude(): float;

    public function contains(float $latitude, float $longitude): bool;
}
```

Testing
-------

[](#testing)

PHPUnit via Composer:

```
composer run-script test
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance91

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~119 days

Recently: every ~144 days

Total

6

Last Release

42d ago

PHP version history (2 changes)v1.0.0PHP ~8.3

v1.1.2PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17726797?v=4)[Vincent Wong](/maintainers/Vectorial1024)[@Vectorial1024](https://github.com/Vectorial1024)

---

Top Contributors

[![Vectorial1024](https://avatars.githubusercontent.com/u/17726797?v=4)](https://github.com/Vectorial1024 "Vectorial1024 (96 commits)")

---

Tags

geogpsopenlocationcodephppluscodegeoopen-location-codeplus-code

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vectorial1024-open-location-code-php/health.svg)

```
[![Health](https://phpackages.com/badges/vectorial1024-open-location-code-php/health.svg)](https://phpackages.com/packages/vectorial1024-open-location-code-php)
```

###  Alternatives

[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k9.3M28](/packages/mjaschen-phpgeo)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k8.5M90](/packages/stevebauman-location)[jmikola/geojson

GeoJSON implementation for PHP

3069.6M90](/packages/jmikola-geojson)[brick/geo

GIS geometry library

2501.3M21](/packages/brick-geo)[geokit/geokit

Geo-Toolkit for PHP

251965.4k6](/packages/geokit-geokit)[geo-io/interface

Geo I/O base interfaces.

626.4M7](/packages/geo-io-interface)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
