PHPackages                             creativefactoryrv/google-maps-geocoder - 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. [Caching](/categories/caching)
4. /
5. creativefactoryrv/google-maps-geocoder

ActiveLibrary[Caching](/categories/caching)

creativefactoryrv/google-maps-geocoder
======================================

Simple and lightweight geocoder that uses the Google Maps Platform API. It can optionally use a PSR cache.

2.1.3(1y ago)030MITPHPPHP &gt;=8.0

Since Sep 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/CreativeFactory-di-Riva-Vigano/google-maps-geocoder)[ Packagist](https://packagist.org/packages/creativefactoryrv/google-maps-geocoder)[ RSS](/packages/creativefactoryrv-google-maps-geocoder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

Google Maps Geocoder
====================

[](#google-maps-geocoder)

A super simple geocoding class that use Google Maps Platform to do the magic.
You only need to obtain a Google **Geocoding API** key ().
Optionally, the class can leverage a PRS-6 cache implementation in order to query the Maps Platform only when necessary.

Install
-------

[](#install)

```
composer require creativefactoryrv/google-maps-geocoder
```

How to use
----------

[](#how-to-use)

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
$latLng = $location->getCoordinates();
echo 'Lat: ' . $latLng['lat'] . ' / Lng: ' . $latLng['lng'];
echo 'ZIP code: ' . $location->getPostalCode();
```

### Get a JSON

[](#get-a-json)

Return the Google Maps Platform API response as it is (JSON).

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
$myJSONString = $location->getRaw();
```

### Get an array

[](#get-an-array)

Return the Google Maps Platform API response as an associative array.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
$myArray = $location->toArray();
```

### Get latitude and longitude

[](#get-latitude-and-longitude)

Returns an array with the desired values.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
$myArray = $location->getCoordinates();
```

### Country

[](#country)

Returns the country value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getCountry();
```

### Locality (city)

[](#locality-city)

Returns the city or locality value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getLocality();
```

### Postal code

[](#postal-code)

Returns the postal code or zipcode value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getPostalCode();
```

### Route (street name)

[](#route-street-name)

Returns the street name (called "route" by Google).

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getRoute();
```

### Street number

[](#street-number)

Returns the street number value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getStreetNumber();
```

### Administrative levels 1

[](#administrative-levels-1)

Returns the administrative levels 1 value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getAdministrativeAreaLevel1();
```

### Administrative levels 2

[](#administrative-levels-2)

Returns the administrative levels 2 value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getAdministrativeAreaLevel2();
```

### Administrative levels 3

[](#administrative-levels-3)

Returns the administrative levels 3 value.

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getAdministrativeAreaLevel3();
```

### Formatted address

[](#formatted-address)

Returns a string representing the address (called "formatted\_address" by Google).

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
echo $location->getFormattedAddress();
```

### Format as you like

[](#format-as-you-like)

Returns a formatted address according to $format.

- %A1 Administrative Area Level 1
- %a1 Administrative Area Level 1 (short version)
- %A2 Administrative Area Level 2
- %a2 Administrative Area Level 2 (short version)
- %A3 Administrative Area Level 3
- %a3 Administrative Area Level 3 (short version)
- %C Country
- %L Locality
- %P Postal code
- %R Route
- %N Street number

```
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en');
$location = $geocoder->query('Duomo, Milano, Italy');
$format = '%R %N, %C';
echo $location->format($format);
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~264 days

Total

4

Last Release

535d ago

Major Versions

1.0.5 → 2.0.12024-11-28

PHP version history (2 changes)1.0.3PHP &gt;=7.0

2.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/da1c6ac20b308c18e247ca36d6a1a22d003542f256402f2dd92760b78dcf725a?d=identicon)[daniele-vigano](/maintainers/daniele-vigano)

---

Top Contributors

[![daniele-vigano](https://avatars.githubusercontent.com/u/86785881?v=4)](https://github.com/daniele-vigano "daniele-vigano (36 commits)")

---

Tags

geocodinggeocodercachecachinggoogle mapsGoogle Maps Platform

### Embed Badge

![Health badge](/badges/creativefactoryrv-google-maps-geocoder/health.svg)

```
[![Health](https://phpackages.com/badges/creativefactoryrv-google-maps-geocoder/health.svg)](https://phpackages.com/packages/creativefactoryrv-google-maps-geocoder)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k348.9M2.5k](/packages/symfony-cache)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[spatie/blink

Cache that expires in the blink of an eye

1685.0M8](/packages/spatie-blink)[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)

PHPackages © 2026

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