Answer the question
In order to leave comments, you need to log in
Geocoder Yandex. How to get the nearest metro from an address in php?
I took all the info from here https://tech.yandex.ru/maps/geocoder/doc/desc/conc... I
got the token here - https://developer.tech.yandex.ru/services/
Here is the code.
$parameters = array(
'apikey' => 'f731a89f-4492-43ff-a822-9de189c2f71e',
'geocode' => 'Москва,+улица+Габричевского,+8',
'kind' => 'metro',
'results' => '1'
);
$response = file_get_contents('https://geocode-maps.yandex.ru/1.x/?'. http_build_query($parameters));
https://geocode-maps.yandex.ru/1.x/?apikey=ваш API-ключ&geocode=37.611347,55.760241&kind=metro&results=1
Answer the question
In order to leave comments, you need to log in
Found a solution. With regards to Iran, the coordinates on the map were simply not perceived correctly (there was 37.611347.55.760241, but it was necessary to change places 55.760241.37.611347, otherwise everything is fine).
It didn’t work for me, because for some reason at the address, he didn’t want to show the metro. But if you insert the coordinates, it showed. Therefore, we make the first request to get the coordinates, and the second - to get the metro.
$address = 'Самара,улица+22+Партсъезда,+15';
$parameters = array(
'apikey' => 'token',
'geocode' => $address, # Самара,улица+22+Партсъезда,+15
'format' => 'json'
);
$response = file_get_contents('https://geocode-maps.yandex.ru/1.x/?'. http_build_query($parameters));
$obj = json_decode($response, true);
$cord = str_replace(" ", ",", $obj['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']);
$parameters = array(
'apikey' => 'token',
'geocode' => $cord,
'kind' => 'metro',
'format' => 'json'
);
$response = file_get_contents('https://geocode-maps.yandex.ru/1.x/?'. http_build_query($parameters));
$obj = json_decode($response, true);
$metro = $obj['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['name'];
echo $metro;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question