Skip to content

snezhkoigor/geocoding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Geocode for Laravel

Requirements

  • PHP >= 7.1.3
  • Laravel >= 5.6

Installation

  1. Install the package via composer:
composer require snezhkoigor/geocoding
  1. 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 Geocoding Service Provider:
// 'providers' => [
    Geocoding\Laravel\GeocodingServiceProvider::class,
// ];

Providers

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)
        ]
    ]
];

Supported Providers

  1. DaData

Customization

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"

Usage

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

Geocoding of Address

app('geocoding')->geocode((\Geocoding\Laravel\Models\Query\GeocodeQuery::create('Π‘Π°Π½ΠΊΡ‚-ΠŸΠ΅Ρ‚Π΅Ρ€Π±ΡƒΡ€Π³')));

Result would be:

{
    "provided_by": "DaData.ru",
    "latitude": 59.9391313,
    "longitude": 30.3159004,
    "address": "Π³ Π‘Π°Π½ΠΊΡ‚-ΠŸΠ΅Ρ‚Π΅Ρ€Π±ΡƒΡ€Π³"
}

Suggest and get Collection of Addresses

app('geocoding')->suggest((\Geocoding\Laravel\Models\Query\SuggestQuery::create('ΠΏΠ΅Ρ€Π²ΠΎ')));

Result would be:

[
    "НиТСгородская ΠΎΠ±Π», Π³ ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊ",
    "ΠšΠΈΡ€ΠΎΠ²ΡΠΊΠ°Ρ ΠΎΠ±Π», ΠΏΠ³Ρ‚ ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ",
    "рСсп Π‘Π°ΡˆΠΊΠΎΡ€Ρ‚ΠΎΡΡ‚Π°Π½, ΠœΠ΅Π»Π΅ΡƒΠ·ΠΎΠ²ΡΠΊΠΈΠΉ Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ",
    "рСсп Π‘Π°ΡˆΠΊΠΎΡ€Ρ‚ΠΎΡΡ‚Π°Π½, БтСрлитамакский Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ",
    "Π§ΡƒΠ²Π°ΡˆΡΠΊΠ°Ρ рСспублика - Π§ΡƒΠ²Π°ΡˆΠΈΡ, БатырСвский Ρ€-Π½, с/ΠΏ ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΎΠ΅",
    "ΠšΡ€Π°ΡΠ½ΠΎΡΡ€ΡΠΊΠΈΠΉ ΠΊΡ€Π°ΠΉ, Манский Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°Π½ΡΠΊΠΈΠΉ",
    "ПСнзСнская ΠΎΠ±Π», КамСнский Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ ΡΠ΅Π»ΡŒΡΠΎΠ²Π΅Ρ‚",
    "рСсп Π‘Π°ΡˆΠΊΠΎΡ€Ρ‚ΠΎΡΡ‚Π°Π½, Π―Π½Π°ΡƒΠ»ΡŒΡΠΊΠΈΠΉ Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ",
    "рСсп Π‘Π°ΡˆΠΊΠΎΡ€Ρ‚ΠΎΡΡ‚Π°Π½, Благоварский Ρ€-Π½, с/с ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΈΠΉ",
    "Π§ΡƒΠ²Π°ΡˆΡΠΊΠ°Ρ рСспублика - Π§ΡƒΠ²Π°ΡˆΠΈΡ, Алатырский Ρ€-Π½, с/ΠΏ ΠŸΠ΅Ρ€Π²ΠΎΠΌΠ°ΠΉΡΠΊΠΎΠ΅"
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages