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.

3.0.0(1mo ago)035MITPHPPHP &gt;=8.0

Since Sep 28Pushed 1mo 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 today

READMEChangelog (4)Dependencies (10)Versions (6)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

43

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Total

5

Last Release

50d ago

Major Versions

1.0.5 → 2.0.12024-11-28

2.1.3 → 3.0.02026-05-13

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

2.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86785881?v=4)[Daniele Viganò](/maintainers/daniele-vigano)[@daniele-vigano](https://github.com/daniele-vigano)

---

Top Contributors

[![daniele-vigano](https://avatars.githubusercontent.com/u/86785881?v=4)](https://github.com/daniele-vigano "daniele-vigano (37 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

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M733](/packages/sylius-sylius)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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