K
K
kevus2018-04-02 20:49:52
API
kevus, 2018-04-02 20:49:52

How to collect metro stations by address (C#, Yandex Maps API)?

Hello. I can thank you financially.
There is a field that contains the address, you need to transform this field into a metro station.
Yandex maps has an API, and there is a method for implementation.
But I can't collect. It is interesting to get not only the result, but also to understand for the future how to assemble it yourself.
API address https://api.yandex.ru/maps/doc/jsapi...erence/geocode.

ymaps.geocode(myMap.getCenter(), {
        /**
         * Опции запроса
         * @see https://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/geocode.xml
         */
        // Ищем только станции метро.
        kind: 'metro',
        // Запрашиваем не более 1 результатов.
        results: 1
    }

var coord = "Москва, Красная площадь", // задаем все переменные и получаем адрес

ymaps.geocode(coord).then(function (res) { // кодируем полученный из coords адрес в коордитаны

// проводим обратное геокодирование и ищем 3 ближайшие станции метро 
        ymaps.geocode(myMap.getCenter(), {
         kind: 'metro',
         results: 3
        }).then(function (met) {
                met.geoObjects.options.set('preset', 'islands#redCircleIcon');
              
                var metro = met.geoObjects;
                      var res = '';
                      met.geoObjects.each(function (obj) {
                        res += obj.properties.get('description') + '***';
                      });
                      
                      $('#metro').text(res);
                  });

And from all this we should get
Was
Moscow, Red Square
Became
Okhotny Ryad
Implementation example in JS
https://codepen.io/anon/pen/pFwhB
https://tech.yandex.ru/maps/jsbox/2.1/reverse_geocode
https ://codepen.io/salpeev/pen/Emsex
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question