Search for nearby metro stations
I want to get a search for the nearest metro stations relative to the original one:
For example, we have the station Vykhino.
I tried to get it using http://geocode-maps.yandex.ru, but it didn't work out.
Here is an example:
$jsonmap = file_get_contents('http://geocode-maps.yandex.ru/1.x/?geocode='.$_REQUEST['metro'].'&kind=metro&format=json');
I only get information about the object, I couldn't even find an approximate implementation of what I need.
2 answers
Look here
https://tech.yandex.ru/maps/doc/jsapi/1.x/ref/reference/metro.closest-docpage/
There of course on js, but I think you will understand
UPD:
// Найдем ближайшую к точке (37.588162, 55.733797) станцию метро
// и покажем ее на карте.
var metro = new YMaps.Metro.Closest(
new YMaps.GeoPoint.(37.588162,55.733797),
{ results: 1 }
);
YMaps.Events.observe(metro, metro.Events.Load, function () {
if (this.length()) {
map.addOverlay(this.get(0));
map.panTo(this.get(0).getGeoPoint())
} else {
alert("Ничего не найдено")
}
});
YMaps.Events.observe(metro, metro.Events.Fault, function (metro, errorMessage) {
alert("Произошла ошибка: " + errorMessage)
});
The kind
parameter is only applicable for reverse geocoding (request by coordinates). Therefore, the coordinates of the station must be passed to it.
In your case, you will need to make two requests to the Geocoder:
-
Determining the coordinates of the Vykhino station
Https://geocode-maps.yandex.ru/1.x/?geocode=metro+Vykhino&format=json&results=1
-
We are looking for the metro stations closest to the point from the results of the previous one request
Important point: when searching for metro stations near the point, the first result will be the Vykhino station itself, because geographically it is closest to the specified coordinates. Therefore, the results should be taken starting from the second one, for this the skip
parameter is added.