1. Go to this page and download the library: Download ajur-media/yandex-geo-coder 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/ */
ajur-media / yandex-geo-coder example snippets
use AJUR\Toolkit\YandexGeoCoder\Api;
звращает mutable object
$api = new Api();
// Можно искать по точке (обратное геокодирование)
// $api->setPoint(30.5166187, 50.4452705);
// Или можно искать по адресу (прямое геокодирование)
$api->setQuery('Санкт-Петербург, Невский проспект, 35');
// Настройка фильтров (можно использовать fluent-интерфейс)
$api
->setLimit(1) // кол-во результатов
->setLang( Api::LANG_RU) // используемый язык для ответа
->setToken('<token>') // api ключ
->load();
$response = $api->getResponse();
echo "Found: ", $response->getFoundCount(), PHP_EOL;
echo "Query: ", $response->getQuery(), PHP_EOL;
$object = $response->getFirst(); // получаем первый (самый релевантный) объект в ответе геокодера
echo "Lat: ", $object->getLatitude(), PHP_EOL;
echo "Lon: ", $object->getLongitude(), PHP_EOL;
// Список найденных объектов
$collection = $response->getList();
foreach ($collection as $n => $item) {
echo "[{$n}] Address: ", $item->getAddress(), PHP_EOL;
echo "Lat: ", $item->getLatitude(), PHP_EOL;
echo "Lon: ", $item->getLongitude(), PHP_EOL;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.