wowworks/geocoder-php-dadata-provider

与 Dadata 建议 API 集成。

v1.1.4 2020-06-05 12:10 UTC

README

地理编码器 DaData 适配器

地理编码器 DaData 适配器。与 Dadata 建议 API 集成。

Latest Stable Version Total Downloads Latest Unstable Version License

安装

此扩展在 packagist.org 上可用,可以通过以下命令使用 composer 安装

composer require wowworks/geocoder-php-dadata-provider

配置

要运行,您需要连接到 wowworks/geocoder-php-dadata-provider

示例

$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();
}