PHPackages                             axelb/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. axelb/geocoder

ActiveLibrary

axelb/geocoder
==============

Geocoding addresses to coordinates

3.3.0(8y ago)0181MITPHPPHP &gt;=5.4.0

Since May 1Pushed 8y ago1 watchersCompare

[ Source](https://github.com/AxelBCreative/geocoder)[ Packagist](https://packagist.org/packages/axelb/geocoder)[ Docs](https://github.com/spatie/geocoder)[ RSS](/packages/axelb-geocoder/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (20)Used By (0)

Geocode addresses to coordinates
================================

[](#geocode-addresses-to-coordinates)

[![Latest Version](https://camo.githubusercontent.com/29a494a723b33f7d65fedc39f9c1adffb2fb56fcc5f2351cfb0d86342607c7fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7370617469652f67656f636f6465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/spatie/geocoder/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/97b409701991c5107aa1b38d6bc49d7f2c9e38520c2e550ed56757c52c3d69c4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f67656f636f6465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/geocoder)[![SensioLabsInsight](https://camo.githubusercontent.com/4cec3d7c008a5df479f552e21816bef567e821ef180efa07c477887ac7fbf85f/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f63306537633731642d333531612d343939362d396437342d3234616266613037343431302e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/c0e7c71d-351a-4996-9d74-24abfa074410)[![StyleCI](https://camo.githubusercontent.com/c550b2a0ca25edc5623857bb0396949ac246d38cfe041a89786ea9fcfb275e57/68747470733a2f2f7374796c6563692e696f2f7265706f732f31393335353433322f736869656c64)](https://styleci.io/repos/19355432)[![Total Downloads](https://camo.githubusercontent.com/8c367e28b2f0e78267cb2c5464c30f918eefa76bb461cd4929e1e0cc8d2ba9a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f67656f636f6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/geocoder)

This package can convert any address to GPS coordinates using [Google's geocoding service](https://developers.google.com/maps/documentation/geocoding/start). Here's a quick example:

```
Geocoder::getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');

// will return this array
[
   'lat' => 51.2343564,
   'lng' => 4.4286108,,
   'accuracy' => 'ROOFTOP',
   'formatted_address' => 'Samberstraat 69, 2060 Antwerpen, Belgium',
   'viewport' => [
       "northeast" => [
            "lat" => 51.23570538029149,
            "lng" => 4.429959780291502
        ],
        "southwest" => [
            "lat" => 51.2330074197085,
            "lng" => 4.427261819708497
        ]
   ]
]
```

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

[](#installation)

You can install this package through composer.

```
composer require spatie/geocoder
```

Laravel installation
--------------------

[](#laravel-installation)

Thought the package works fine in non-Laravel projects we included some niceties for our fellow artistans.

In Laravel 5.5 the package will autoregister itself. In older versions of Laravel your must manually installed the service provider and facade.

```
// config/app.php
'providers' => [
    '...',
    Spatie\Geocoder\GeocoderServiceProvider::class
];
```

```
// config/app.php
'aliases' => array(
	...
	'Geocoder' => Spatie\Geocoder\Facades\Geocoder::class,
)
```

Next, you must publish the config file :

```
php artisan vendor:publish --provider="Spatie\Geocoder\GeocoderServiceProvider" --tag="config"
```

This is the content of the config file:

```
return [

   /*
    * The api key used when sending Geocoding requests to Google.
    */
   'key' => env('GOOGLE_MAPS_GEOCODING_API_KEY', ''),

   /*
    * The language param used to set response translations for textual data.
    *
    * More info: https://developers.google.com/maps/faq#languagesupport
    */

   'language' => '',

   /*
    * The region param used to finetune the geocoding process.
    *
    * More info: https://developers.google.com/maps/documentation/geocoding/intro#RegionCodes
    */
   'region' => '',

    /*
     * The bounds param used to finetune the geocoding process.
     *
     * More info: https://developers.google.com/maps/documentation/geocoding/intro#Viewports
     */
    'bounds' => '',

];
```

Usage
-----

[](#usage)

Here's how you can use the Geocoder.

```
$client = new GuzzleHttp\Client();

$geocoder = new Geocoder($client);

$geocoder->getCoordinatesForAddress('Infinite Loop 1, Cupertino', $apiKey);

/*
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "formatted_address" => "1 Infinite Loop, Cupertino, CA 95014, USA",
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/
```

You can get the result back in a specific language.

```
$geocoder
   ->getCoordinatesForAddress('Infinite Loop 1, Cupertino')
   ->setLanguage('it');

/*
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/
```

This is how you can reverse geocode coordinates to addresses.

```
$geocoder->getAddressForCoordinates(40.714224, -73.961452);

/*
  This function returns an array with keys
  "lat" => 40.7142205
  "lng" => -73.9612903
  "accuracy" => "ROOFTOP"
  "formatted_address" => "277 Bedford Ave, Brooklyn, NY 11211, USA",
  "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/
```

If you are using the package with Laravel, you can simply call `getCoordinatesForAddress`.

```
Geocoder::getCoordinatesForAddress('Infinite Loop 1, Cupertino');

/*
  This function returns an array with keys
  "lat" =>  37.331741000000001
  "lng" => -122.0303329
  "accuracy" => "ROOFTOP"
  "formatted_address" => "1 Infinite Loop, Cupertino, CA 95014, Stati Uniti",
    "viewport" => [
    "northeast" => [
      "lat" => 37.3330546802915,
      "lng" => -122.0294342197085
    ],
    "southwest" => [
      "lat" => 37.3303567197085,
      "lng" => -122.0321321802915
    ]
  ]
*/
```

The accuracy key can contain these values:

- `ROOFTOP`
- `RANGE_INTERPOLATED`
- `GEOMETRIC_CENTER`
- `APPROXIMATE`

You can read more information about these values [on the Google Geocoding API Page](https://developers.google.com/maps/documentation/geocoding/ "Google Geocoding API")

When an address is not found accuracy and formatted\_address will contain `NOT_FOUND`

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~85 days

Recently: every ~44 days

Total

18

Last Release

2946d ago

Major Versions

0.1.2 → 1.0.02015-05-23

1.0.0 → 2.0.02015-06-12

2.3.2 → 3.0.02017-10-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/7cd5d8a69be5bb5f4a86b4665480911aa38b69c671bef682345ce5ec8fcecc45?d=identicon)[axelb](/maintainers/axelb)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (80 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (3 commits)")[![michelecurletta](https://avatars.githubusercontent.com/u/65455871?v=4)](https://github.com/michelecurletta "michelecurletta (2 commits)")[![hellozach](https://avatars.githubusercontent.com/u/8039641?v=4)](https://github.com/hellozach "hellozach (2 commits)")[![AxelBCreative](https://avatars.githubusercontent.com/u/2568323?v=4)](https://github.com/AxelBCreative "AxelBCreative (2 commits)")[![GregorVoelkl](https://avatars.githubusercontent.com/u/8426676?v=4)](https://github.com/GregorVoelkl "GregorVoelkl (2 commits)")[![lloy0076](https://avatars.githubusercontent.com/u/1174532?v=4)](https://github.com/lloy0076 "lloy0076 (2 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (1 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (1 commits)")[![caiquecastro](https://avatars.githubusercontent.com/u/3316550?v=4)](https://github.com/caiquecastro "caiquecastro (1 commits)")[![gpluess](https://avatars.githubusercontent.com/u/598360?v=4)](https://github.com/gpluess "gpluess (1 commits)")[![juukie](https://avatars.githubusercontent.com/u/2678657?v=4)](https://github.com/juukie "juukie (1 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (1 commits)")[![repat](https://avatars.githubusercontent.com/u/516807?v=4)](https://github.com/repat "repat (1 commits)")

---

Tags

laravelmaplocationgeocodecoordinate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/axelb-geocoder/health.svg)

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

###  Alternatives

[spatie/geocoder

Geocoding addresses to coordinates

8404.8M15](/packages/spatie-geocoder)[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[spatie/google-time-zone

Get time zones for coordinates

110660.6k1](/packages/spatie-google-time-zone)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)

PHPackages © 2026

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