PHP code example of wowworks / geocoder-php-dadata-provider

1. Go to this page and download the library: Download wowworks/geocoder-php-dadata-provider 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/ */

    

wowworks / geocoder-php-dadata-provider example snippets


$service = new \DadataSuggestions\DadataSuggestionsService();
$service->setUrl('https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/');
$service->setToken('...');
$dadataProvider = new \Wowworks\Dadata\Dadata($service);
$collection = $dadataProvider->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('г Москва, улица Академика Королева, дом 15, корп. 2'));
foreach ($collection->all() as $location) {
    $location->getCoordinates()->getLatitude();
    $location->getCoordinates()->getLongitude();

    $location->getCountry();
    foreach ($location->getAdminLevels() as $level) {
        if ($level instanceof AdminLevel) {
            $level->getName();
        }
    }
    $location->getLocality();
    $location->getSubLocality();
    $location->getStreetName();
    $location->getStreetNumber();
    $location->getProvidedBy();
}