PHPackages                             deondazy/geocoder-laravel - 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. [API Development](/categories/api)
4. /
5. deondazy/geocoder-laravel

ActiveLibrary[API Development](/categories/api)

deondazy/geocoder-laravel
=========================

Geocoder Service Provider for Laravel

v1.0.0(1y ago)001MITPHPPHP ^8.0

Since Feb 27Pushed 1y agoCompare

[ Source](https://github.com/deondazy/GeocoderLaravel)[ Packagist](https://packagist.org/packages/deondazy/geocoder-laravel)[ Docs](http://geocoder-php.org/)[ RSS](/packages/deondazy-geocoder-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (20)Versions (2)Used By (1)

[![Travis](https://camo.githubusercontent.com/e65db95fd33bd74e33728a579aad10159b075faf8e943b99a85093004bdf3a4c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f67656f636f6465722d7068702f47656f636f6465724c61726176656c2e737667)](https://travis-ci.org/geocoder-php/GeocoderLaravel)[![Scrutinizer](https://camo.githubusercontent.com/f4ff27b7d964a68f2b1c8126c82244c71011b4874edba11e93930212a4549caa/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f67656f636f6465722d7068702f47656f636f6465724c61726176656c2e737667)](https://scrutinizer-ci.com/g/geocoder-php/GeocoderLaravel/)[![Coveralls](https://camo.githubusercontent.com/bbecf8e99948613f8aaf82dc02ffd143f4780a2205e2432c5df958a3b20cf10e/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f67656f636f6465722d7068702f47656f636f6465724c61726176656c2e737667)](https://coveralls.io/github/geocoder-php/GeocoderLaravel)[![GitHub release](https://camo.githubusercontent.com/eae937590ea14270bad6cb6d64b0a48bcef6a41d36eb55e17f9dc55ef581b060/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67656f636f6465722d7068702f47656f636f6465724c61726176656c2e737667)](https://github.com/geocoder-php/GeocoderLaravel/releases)[![Packagist](https://camo.githubusercontent.com/3233d9a5e322d61ba2000e501fe0799b984870d0af32d608b96136e0e533582d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f696e30752f67656f636f6465722d6c61726176656c2e737667)](https://packagist.org/packages/toin0u/geocoder-laravel)

Geocoder for Laravel
====================

[](#geocoder-for-laravel)

> If you still use **Laravel 4**, please check out the `0.4.x` branch [here](https://github.com/geocoder-php/GeocoderLaravel/tree/0.4.x).

**Version 4.0.0 is a backwards-compatibility-breaking update. Please review this documentation, especially the *Usage* section before installing.**

This package allows you to use [**Geocoder**](http://geocoder-php.org/Geocoder/)in [**Laravel 5**](http://laravel.com/).

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1.3
- Laravel &gt;= 5.0

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

[](#installation)

1. Install the package via composer:

```
composer require toin0u/geocoder-laravel
```

2. **If you are running Laravel 5.5 (the package will be auto-discovered), skip this step.** Find the `providers` array key in `config/app.php` and register the **Geocoder Service Provider**:

```
// 'providers' => [
    Geocoder\Laravel\Providers\GeocoderService::class,
// ];
```

3. **Optional** I recommend adding the following lines to your `composer.json` file to prevent stale caches when upgrading or updating the package, both in your live and dev environments:

```
        "post-update-cmd": [
            "@php artisan cache:clear",
        ],
        "post-install-cmd": [
            "@php artisan cache:clear",
        ]
```

Configuration
-------------

[](#configuration)

Pay special attention to the language and region values if you are using them. For example, the GoogleMaps provider uses TLDs for region values, and the following for language values: .

Further, a special note on the GoogleMaps provider: if you are using an API key, you must also use set HTTPS to true. (Best is to leave it true always, unless there is a special requirement not to.)

See the [Geocoder documentation](http://geocoder-php.org/Geocoder/) for a list of available adapters and providers.

### Dedicated Cache Store *Recommended*

[](#dedicated-cache-store-recommended)

To implement the dedicated cache store, add another redis store entry in `config/database.php`, something like the following:

```
    "redis" => [
        // ...

        "geocode-cache" => [ // choose an appropriate name
            'host' => env('REDIS_HOST', '192.168.10.10'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 1, // be sure this number differs from your other redis databases
        ],
    ]
```

You will also need to add an entry in `config/cache.php` to point to this redis database:

```
    "stores" => [
        // ...

        "geocode" => [
            'driver' => 'redis',
            'connection' => 'geocode-cache',
        ],
    ],
```

Finally, configure Geocoder for Laravel to use this store. Edit `config/geocoder.php`:

```
    "cache" => [
        "store" => "geocode",

        // ...
    ],
```

#### Disabling Caching on a Query-Basis

[](#disabling-caching-on-a-query-basis)

You can disable caching on a query-by-query basis as needed, like so:

```
    $results = app("geocoder")
        ->doNotCache()
        ->geocode('Los Angeles, CA')
        ->get();
```

### Providers

[](#providers)

If you are upgrading and have previously published the geocoder config file, you need to add the `cache-duration` variable, otherwise cache will be disabled (it will default to a `0` cache duration). The default cache duration provided by the config file is `999999999` seconds, essentially forever.

By default, the configuration specifies a Chain provider, containing the GoogleMaps provider for addresses as well as reverse lookups with lat/long, and the GeoIP provider for IP addresses. The first to return a result will be returned, and subsequent providers will not be executed. The default config file is kept lean with only those two providers.

However, you are free to add or remove providers as needed, both inside the Chain provider, as well as along-side it. The following is the default configuration provided by the package:

```
use Geocoder\Provider\Chain\Chain;
use Geocoder\Provider\GeoPlugin\GeoPlugin;
use Geocoder\Provider\GoogleMaps\GoogleMaps;
use Http\Client\Curl\Client;

return [

    /*
    |--------------------------------------------------------------------------
    | Cache Duration
    |--------------------------------------------------------------------------
    |
    | Specify the cache duration in seconds. The default approximates a forever
    | cache, but there are certain issues with Laravel's forever caching
    | methods that prevent us from using them in this project.
    |
    | Default: 9999999 (integer)
    |
    */
    'cache-duration' => 9999999,

    /*
    |--------------------------------------------------------------------------
    | Providers
    |--------------------------------------------------------------------------
    |
    | Here you may specify any number of providers that should be used to
    | perform geocaching operations. The `chain` provider is special,
    | in that it can contain multiple providers that will be run in
    | the sequence listed, should the previous provider fail. By
    | default the first provider listed will be used, but you
    | can explicitly call subsequently listed providers by
    | alias: `app('geocoder')->using('google_maps')`.
    |
    | Please consult the official Geocoder documentation for more info.
    | https://github.com/geocoder-php/Geocoder#providers
    |
    */
    'providers' => [
        Chain::class => [
            GoogleMaps::class => [
                env('GOOGLE_MAPS_LOCALE', 'us'),
                env('GOOGLE_MAPS_API_KEY'),
            ],
            GeoPlugin::class  => [],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Adapter
    |--------------------------------------------------------------------------
    |
    | You can specify which PSR-7-compliant HTTP adapter you would like to use.
    | There are multiple options at your disposal: CURL, Guzzle, and others.
    |
    | Please consult the official Geocoder documentation for more info.
    | https://github.com/geocoder-php/Geocoder#usage
    |
    | Default: Client::class (FQCN for CURL adapter)
    |
    */
    'adapter'  => Client::class,

    /*
    |--------------------------------------------------------------------------
    | Reader
    |--------------------------------------------------------------------------
    |
    | You can specify a reader for specific providers, like GeoIp2, which
    | connect to a local file-database. The reader should be set to an
    | instance of the required reader class or an array containing the reader
    | class and arguments.
    |
    | Please consult the official Geocoder documentation for more info.
    | https://github.com/geocoder-php/geoip2-provider
    |
    | Default: null
    |
    */
    'reader' => null,

];
```

### Adapters

[](#adapters)

By default we provide a CURL adapter to get you running out of the box. However, if you have already installed Guzzle or any other PSR-7-compatible HTTP adapter, you are encouraged to replace the CURL adapter with it. Please see the [Geocoder Documentation](https://github.com/geocoder-php/Geocoder) for specific implementation details.

### Customization

[](#customization)

If you would like to make changes to the default configuration, publish and edit the configuration file:

```
php artisan vendor:publish --provider="Geocoder\Laravel\Providers\GeocoderService" --tag="config"
```

Usage
-----

[](#usage)

The service provider initializes the `geocoder` service, accessible via the facade `Geocoder::...` or the application helper `app('geocoder')->...`.

### Geocoding Addresses

[](#geocoding-addresses)

#### Get Collection of Addresses

[](#get-collection-of-addresses)

```
app('geocoder')->geocode('Los Angeles, CA')->get();
```

#### Get IP Address Information

[](#get-ip-address-information)

```
app('geocoder')->geocode('8.8.8.8')->get();
```

#### Reverse-Geocoding

[](#reverse-geocoding)

```
app('geocoder')->reverse(43.882587,-103.454067)->get();
```

#### Dumping Results

[](#dumping-results)

```
app('geocoder')->geocode('Los Angeles, CA')->dump('kml');
```

#### Dependency Injection

[](#dependency-injection)

```
use Geocoder\Laravel\ProviderAndDumperAggregator as Geocoder;

class GeocoderController extends Controller
{
    public function getGeocode(Geocoder $geocoder)
    {
       $geocoder->geocode('Los Angeles, CA')->get()
    }
}
```

Upgrading
---------

[](#upgrading)

Anytime you upgrade this package, please remember to clear your cache, to prevent incompatible cached responses when breaking changes are introduced (this should hopefully only be necessary in major versions):

```
php artisan cache:clear
```

### 1.x to 4.x

[](#1x-to-4x)

Update your composer.json file:

```
    "toin0u/geocoder-laravel": "^4.0",
```

The one change to keep in mind here is that the results returned from `Geocoder for Laravel` are now using the Laravel-native Collections class instead of returning an instance of `AddressCollection`. This should provide greater versatility in manipulation of the results, and be inline with expectations for working with Laravel. The existing `AddressCollection`methods should map straight over to Laravel's `Collection` methods. But be sure to double-check your results, if you have been using `count()`, `first()`, `isEmpty()`, `slice()`, `has()`, `get()`, or `all()` on your results.

Also, `getProviders()` now returns a Laravel Collection instead of an array.

**Alert:** if you have been using the `getIterator()` method, it is no longer needed. Simply iterate over your results as you would any other Laravel collection.

**Deprecated:**

- the `all()` method on the geocoder is being deprecated in favor of using `get()`, which will return a Laravel Collection. You can then run `all()`on that. This method will be removed in version 5.0.0.
- the `getProvider()` method on the geocoder is being deprecated in favor of using `getProviders()`, which will return a Laravel Collection. You can then run `first()`on that to get the same result. This method will be removed in version 5.0.0.

**Added:** this version introduces a new way to create more complex queries:

- geocodeQuery()
- reverseQuery()

Please see the [Geocoder documentation](https://github.com/geocoder-php/Geocoder)for more details.

### 0.x to 1.x

[](#0x-to-1x)

If you are upgrading from a pre-1.x version of this package, please keep the following things in mind:

1. Update your composer.json file as follows:

    ```
    "toin0u/geocoder-laravel": "^1.0",
    ```
2. Remove your `config/geocoder.php` configuration file. (If you need to customize it, follow the configuration instructions below.)
3. Remove any Geocoder alias in the aliases section of your `config/app.php`. (This package auto-registers the aliases.)
4. Update the service provider entry in your `config/app.php` to read:

    ```
    Geocoder\Laravel\Providers\GeocoderService::class,
    ```
5. If you are using the facade in your code, you have two options:

    1. Replace the facades `Geocoder::` (and remove the corresponding `use` statements) with `app('geocoder')->`.
    2. Update the `use` statements to the following:

        ```
        use Geocoder\Laravel\Facades\Geocoder;
        ```
6. Update your query statements to use `->get()` (to retrieve a collection of GeoCoder objects) or `->all()` (to retrieve an array of arrays), then iterate to process each result.

Troubleshooting
---------------

[](#troubleshooting)

- Clear cache: `php artisan cache:clear`.
- If you are still experiencing difficulties, please please open an issue on GitHub: .

Changelog
---------

[](#changelog)

Contributor Code of Conduct
---------------------------

[](#contributor-code-of-conduct)

Please note that this project is released with a [Contributor Code of Conduct](https://github.com/geocoder-php/Geocoder#contributor-code-of-conduct). By participating in this project you agree to abide by its terms.

License
-------

[](#license)

GeocoderLaravel is released under the MIT License. See the bundled [LICENSE](https://github.com/geocoder-php/GeocoderLaravel/blob/master/LICENSE)file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance44

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70.4% 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

Unknown

Total

1

Last Release

444d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f1c1a5b25865f0e67ca1a7d172fed5e6a7b1adb9339674341a8f1b0dbcee652?d=identicon)[deondazy](/maintainers/deondazy)

---

Top Contributors

[![mikebronner](https://avatars.githubusercontent.com/u/1791050?v=4)](https://github.com/mikebronner "mikebronner (221 commits)")[![toin0u](https://avatars.githubusercontent.com/u/672421?v=4)](https://github.com/toin0u "toin0u (43 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (7 commits)")[![spinegar](https://avatars.githubusercontent.com/u/2236579?v=4)](https://github.com/spinegar "spinegar (6 commits)")[![willdurand](https://avatars.githubusercontent.com/u/217628?v=4)](https://github.com/willdurand "willdurand (4 commits)")[![msschl](https://avatars.githubusercontent.com/u/5054780?v=4)](https://github.com/msschl "msschl (3 commits)")[![matthewbdaly](https://avatars.githubusercontent.com/u/450801?v=4)](https://github.com/matthewbdaly "matthewbdaly (2 commits)")[![anaxamaxan](https://avatars.githubusercontent.com/u/439457?v=4)](https://github.com/anaxamaxan "anaxamaxan (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![macbookandrew](https://avatars.githubusercontent.com/u/784333?v=4)](https://github.com/macbookandrew "macbookandrew (2 commits)")[![anam-hossain](https://avatars.githubusercontent.com/u/5017268?v=4)](https://github.com/anam-hossain "anam-hossain (2 commits)")[![nmfzone](https://avatars.githubusercontent.com/u/10361906?v=4)](https://github.com/nmfzone "nmfzone (2 commits)")[![CWSpear](https://avatars.githubusercontent.com/u/495855?v=4)](https://github.com/CWSpear "CWSpear (1 commits)")[![liuggio](https://avatars.githubusercontent.com/u/530406?v=4)](https://github.com/liuggio "liuggio (1 commits)")[![tooblue](https://avatars.githubusercontent.com/u/4994461?v=4)](https://github.com/tooblue "tooblue (1 commits)")[![verkaufer](https://avatars.githubusercontent.com/u/680527?v=4)](https://github.com/verkaufer "verkaufer (1 commits)")[![Dylan-DPC](https://avatars.githubusercontent.com/u/99973273?v=4)](https://github.com/Dylan-DPC "Dylan-DPC (1 commits)")[![dwenaus](https://avatars.githubusercontent.com/u/393655?v=4)](https://github.com/dwenaus "dwenaus (1 commits)")[![nabilelmahiri](https://avatars.githubusercontent.com/u/19693601?v=4)](https://github.com/nabilelmahiri "nabilelmahiri (1 commits)")[![canvural](https://avatars.githubusercontent.com/u/1574232?v=4)](https://github.com/canvural "canvural (1 commits)")

---

Tags

laravelgeocodinggeocoder

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[toin0u/geocoder-laravel

Geocoder Service Provider for Laravel

7385.1M13](/packages/toin0u-geocoder-laravel)[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.5M84](/packages/irazasyed-telegram-bot-sdk)[willdurand/geocoder-bundle

Integration of Geocoder into Symfony

3226.4M12](/packages/willdurand-geocoder-bundle)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)

PHPackages © 2026

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