PHPackages                             spatie/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/geocoder

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

spatie/geocoder
===============

Geocoding addresses to coordinates

4.0.0(2mo ago)8404.8M—9.7%11312MITPHPPHP ^8.3CI passing

Since May 1Pushed 2mo ago18 watchersCompare

[ Source](https://github.com/spatie/geocoder)[ Packagist](https://packagist.org/packages/spatie/geocoder)[ Docs](https://github.com/spatie/geocoder)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-geocoder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (48)Used By (12)

 [   ![Logo for Geocoder](https://camo.githubusercontent.com/c0feab8bbac8cb186f0fff954492e604529d96931fa7b292ce85f8f12dea3428/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f67656f636f6465722f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=geocoder)Geocode Addresses into Coordinates
==================================

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

[![Latest Version](https://camo.githubusercontent.com/29a494a723b33f7d65fedc39f9c1adffb2fb56fcc5f2351cfb0d86342607c7fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7370617469652f67656f636f6465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/spatie/geocoder/releases)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://github.com/spatie/geocoder/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/geocoder/actions/workflows/run-tests.yml)[![Check & fix styling](https://github.com/spatie/geocoder/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/spatie/geocoder/workflows/Check%20&%20fix%20styling/badge.svg)[![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
        ]
   ]
]
```

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

[](#support-us)

Learn how to create a package like this one, by watching our premium video course:

[![Laravel Package training](https://camo.githubusercontent.com/4c7f3720a29525e627f6004ee367e55def510e45d18e6bc974725812fa5cf257/68747470733a2f2f7370617469652e62652f6769746875622f7061636b6167652d747261696e696e672e6a7067)](https://laravelpackage.training)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install this package through composer.

```
composer require spatie/geocoder
```

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

[](#laravel-installation)

Though 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 you must manually install 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' => '',

     /*
     * The country param used to limit results to a specific country.
     *
     * More info: https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests
     */
    'country' => '',
];
```

Usage
-----

[](#usage)

Here's how you can use the Geocoder.

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

$geocoder = new Geocoder($client);

$geocoder->setApiKey(config('geocoder.key'));

$geocoder->setCountry(config('geocoder.country', 'US'));

$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, 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->setLanguage('it');

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

/*
  This function returns an array with keys
  "lat" => 37,3318598
  "lng" => -122,0302485
  "accuracy" => "ROOFTOP"
  "formatted_address" => "Infinite Loop 1, 1 Infinite Loop, Cupertino, CA 95014, Stati Uniti"
  ...
*/
```

You can also get all the results instead of the first one

```
$geocoder
   ->getAllCoordinatesForAddress('Infinite Loop 1, Cupertino');

/*
  This function returns an array of results (array of array)
  ^ array:2 [
      0 => array:7 [
        "lat" => 37,3318115
        "lng" => -122,0301837
        "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
          ]
        ]
        "place_id" => "ChIJHTRqF7e1j4ARzZ_Fv8VA4Eo"
      ]
      1 => array:7 [
        "lat" => 37,3318598
        "lng" => -122,0302485
        "accuracy" => "ROOFTOP"
        "formatted_address" => "Infinite Loop 1, 1 Infinite Loop, Cupertino, CA 95014, Stati Uniti"
        "viewport" => [
          "northeast" => [
            "lat" => 37.333046180291
            "lng" => -122.02883961971
          ],
          "southwest" => [
            "lat" => 37.330348219708
            "lng" => -122.03153758029
          ]
        ]
        "place_id" => "ChIJAf9D3La1j4ARuwKZtGjgMXw"
      ]
    ]
*/
```

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
    ]
  ]
*/
```

You can also reverse geocode coordinates to all the related addresses.

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

/*
  This function returns an array of results (array of array)
  array:2 [
    0 => array: 7 [
      "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
        ]
      ]
    ],
    1 => array: 7 [
      "lat" => 40.7142015
      "lng" => -73.9613077
      "accuracy" => "ROOFTOP"
      "formatted_address" => "279 Bedford Ave, Brooklyn, NY 11211, USA",
      "viewport" => [
        "northeast" => [
          "lat" => 40.715557080291,
          "lng" => -73.959947169708
        ],
        "southwest" => [
          "lat" => 40.712859119708,
          "lng" => -73.962645130291
        ]
      ]
    ]
  ]
*/
```

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 `result_not_found`

Credits
-------

[](#credits)

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

License
-------

[](#license)

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

###  Health Score

74

—

ExcellentBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity67

Solid adoption and visibility

Community42

Growing community involvement

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63.9% 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 ~100 days

Recently: every ~214 days

Total

44

Last Release

87d 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

3.16.2 → 4.0.02026-02-20

PHP version history (5 changes)0.1.1PHP &gt;=5.4.0

3.3.1PHP &gt;=7.0

3.5.0PHP ^7.2

3.9.3PHP ^7.2|^8.0

4.0.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (129 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (14 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (8 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (8 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (5 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![jimirobaer](https://avatars.githubusercontent.com/u/8984769?v=4)](https://github.com/jimirobaer "jimirobaer (3 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (3 commits)")[![GregorVoelkl](https://avatars.githubusercontent.com/u/8426676?v=4)](https://github.com/GregorVoelkl "GregorVoelkl (2 commits)")[![hellozach](https://avatars.githubusercontent.com/u/8039641?v=4)](https://github.com/hellozach "hellozach (2 commits)")[![jpeters8889](https://avatars.githubusercontent.com/u/30417702?v=4)](https://github.com/jpeters8889 "jpeters8889 (2 commits)")[![lloy0076](https://avatars.githubusercontent.com/u/1174532?v=4)](https://github.com/lloy0076 "lloy0076 (2 commits)")[![michelecurletta](https://avatars.githubusercontent.com/u/65455871?v=4)](https://github.com/michelecurletta "michelecurletta (2 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (2 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (2 commits)")[![bluec](https://avatars.githubusercontent.com/u/1577895?v=4)](https://github.com/bluec "bluec (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![BackEndTea](https://avatars.githubusercontent.com/u/14289961?v=4)](https://github.com/BackEndTea "BackEndTea (1 commits)")[![jinseokoh](https://avatars.githubusercontent.com/u/1305356?v=4)](https://github.com/jinseokoh "jinseokoh (1 commits)")[![tonyjaimep](https://avatars.githubusercontent.com/u/26732004?v=4)](https://github.com/tonyjaimep "tonyjaimep (1 commits)")

---

Tags

addressgeogeocodergooglephplaravelmaplocationgeocodecoordinate

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[adrianorosa/laravel-geolocation

Laravel Geo Location package to get details for a given IP Address

6593.3k1](/packages/adrianorosa-laravel-geolocation)

PHPackages © 2026

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