0

I need to get coordidinates of set of addresses to display them on Yandex Map widget. There a lot of addresses, so I am going to get coordinates on the nodejs serverside. I have found package multi-geocoder, that looks exactly the solution for me. So I've written the example:

import MultiGeocoder from "multi-geocoder"

const geocoder = new MultiGeocoder({        
    provider: 'yandex',
    coordorder: 'latlong',
    lang: 'ru-RU',
    apikey: 'My API key from https://developer.tech.yandex.ru/'
});

geocoder.geocode(['Москва'], {
    apikey: 'My API key from https://developer.tech.yandex.ru/'
})
.then(function (res) {
    console.log(res);
});

I got the response:

{
   result: { type: 'FeatureCollection', features: [] },
   errors: [ { request: 'Москва', index: 0, reason: 'Forbidden' } ]
}

I assume that something went wrong with apiKey, but cant figure out what exactly. How to get coordinates properly from nodejs script? Is it possible\legal at all?

Thank you.

KozhevnikovDmitry
  • 1,660
  • 12
  • 27

1 Answers1

1

If you have any problems with the API key, you should contact Yandex. Maps support. The problem may be with the key itself, or with your IP/domain. Only Yandex can determine the exact cause.

If you need to add points from the geocoder to the map, then it is easier to use geocoding in the JS API. It is enough to simply sequentially process the elements of the address array:

var searchArr = ['Москва, Фадеева, 5','Москва, Трубная, 31','Москва, Маросейка, 11'];

searchArr.forEach(function(item) {
    ymaps.geocode(item, {
    results: 1
}).then(function (res) {
        var firstGeoObject = res.geoObjects.get(0),
            coords = firstGeoObject.geometry.getCoordinates();
        myMap.geoObjects.add(firstGeoObject);
    });
});

If you display the data received from the data on a Yandex map and follow the other terms of use, the Yandex.Map API is available for free. If at least one of the conditions must be violated, you should switch to a commercial license. Check out the fees here: https://tech.yandex.com/maps/tariffs/doc/jsapi/prices/index-docpage/

YaCor'
  • 121
  • 3