PHP code example of toin0u / geocoder-laravel

1. Go to this page and download the library: Download toin0u/geocoder-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toin0u / geocoder-laravel example snippets


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

    "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
        ],
    ]

    "stores" => [
        // ...

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

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

        // ...
    ],

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

    'cache' => [
        // ...

        'auto_register_serializable_classes' => false,
    ],

use Geocoder\Laravel\Http\LaravelHttpClient;
use Geocoder\Provider\Chain\Chain;
use Geocoder\Provider\GeoPlugin\GeoPlugin;
use Geocoder\Provider\GoogleMaps\GoogleMaps;

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
    |--------------------------------------------------------------------------
    |
    | The HTTP adapter to use when communicating with geocoding services. By
    | default this package ships a PSR-18 client that delegates to Laravel's
    | `Http` facade — this gives you `Http::fake()` in tests, native retry
    | and timeout configuration, and any HTTP middleware you've registered.
    |
    | Provide any class that implements `Psr\Http\Client\ClientInterface` to
    | swap in a different adapter (e.g., `Http\Client\Curl\Client` from
    | `php-http/curl-client`, which you would need to install separately).
    |
    | To pass constructor arguments (timeouts, proxies, client options, etc.)
    | use the array form `[Class => [args]]`. Arguments are forwarded to the
    | adapter's constructor — it's on you to match its signature. Named args
    | are supported: `[Class => ['timeout' => 10]]`.
    |
    | Default: LaravelHttpClient::class
    |
    | Examples:
    |   'adapter' => LaravelHttpClient::class,
    |   'adapter' => [LaravelHttpClient::class => ['timeout' => 10, 'retry' => [3, 100]]],
    |   'adapter' => [Http\Client\Curl\Client::class => [null, null, [CURLOPT_PROXY => '...']]],
    |
    */
    'adapter'  => LaravelHttpClient::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 

'adapter' => [LaravelHttpClient::class => [
    'timeout' => 10,
    'connectTimeout' => 3,
    'retry' => [3, 100],             // [times, sleepMilliseconds]
    'options' => ['verify' => false], // Guzzle transport options
]],

'adapter' => [Http\Client\Curl\Client::class => [
    null,
    null,
    [CURLOPT_PROXY => env('CURL_PROXY'), CURLOPT_PROXYUSERPWD => env('CURL_PROXYUSERPWD')],
]],

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

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

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

app('geocoder')->locale('it')->geocode('Bologna')->get();
app('geocoder')->locale('fr')->reverse(45.5, -73.5)->get();

use Geocoder\Query\GeocodeQuery;

$query = GeocodeQuery::create('Bologna')->withLocale('it');
app('geocoder')->geocodeQuery($query)->get();

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

use Geocoder\Laravel\ProviderAndDumperAggregator as Geocoder;

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

    Geocoder\Laravel\Providers\GeocoderService::class,
    

        use Geocoder\Laravel\Facades\Geocoder;
        
json
        "post-update-cmd": [
            "@php artisan cache:clear",
        ],
        "post-install-cmd": [
            "@php artisan cache:clear",
        ]
sh
php artisan vendor:publish --provider="Geocoder\Laravel\Providers\GeocoderService" --tag="config"
sh
php artisan cache:clear