- PHP >= 7.1.3
- Laravel >= 5.6
- Install the package via composer:
composer require snezhkoigor/geocoding- If you are running Laravel 5.5 (the package will be auto-discovered), skip this step. Find the
providersarray key inconfig/app.phpand register the Geocoding Service Provider:
// 'providers' => [ Geocoding\Laravel\GeocodingServiceProvider::class, // ];By default, the configuration specifies a Chain provider, containing the GoogleMaps provider for addresses as well as reverse lookups with lat/long.
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:
<?php use Geocoding\Laravel\Providers\DaData; return [ /* |-------------------------------------------------------------------------- | Providers |-------------------------------------------------------------------------- | */ 'providers' => [ DaData::class => [ 'token' => env('DADATA_TOKEN', ''), 'proxy' => env('DADATA_PROXY_IP', null) ] ] ]; - DaData
If you would like to make changes to the default configuration, publish and edit the configuration file:
php artisan vendor:publish --provider="Geocoding\Laravel\GeocodingServiceProvider" --tag="config"The service provider initializes the geocoding service, accessible via the facade Geocoding::... or the application helper app('geocoding')->....
app('geocoding')->geocode((\Geocoding\Laravel\Models\Query\GeocodeQuery::create('Санкт-Петербург')));Result would be:
{ "provided_by": "DaData.ru", "latitude": 59.9391313, "longitude": 30.3159004, "address": "г Санкт-Петербург" } app('geocoding')->suggest((\Geocoding\Laravel\Models\Query\SuggestQuery::create('перво')));Result would be:
[ "Нижегородская обл, г Первомайск", "Кировская обл, пгт Первомайский", "респ Башкортостан, Мелеузовский р-н, с/с Первомайский", "респ Башкортостан, Стерлитамакский р-н, с/с Первомайский", "Чувашская республика - Чувашия, Батыревский р-н, с/п Первомайское", "Красноярский край, Манский р-н, с/с Первоманский", "Пензенская обл, Каменский р-н, с/с Первомайский сельсовет", "респ Башкортостан, Янаульский р-н, с/с Первомайский", "респ Башкортостан, Благоварский р-н, с/с Первомайский", "Чувашская республика - Чувашия, Алатырский р-н, с/п Первомайское" ]