通过NodeJs中的多地理编码器从Yandex Map API Geocoder获取坐标

问题描述 投票:0回答:1

我需要获取地址集的坐标才能在Yandex Map小部件上显示它们。地址很多,因此我将在nodejs服务器端获取坐标。我找到了软件包multi-geocoder,对我来说正是解决方案。因此,我编写了示例:

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);
});

我得到了答复:

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

我假设apiKey出了点问题,但是无法弄清楚到底是什么。如何从Node.js脚本正确获取坐标?可能\合法吗?

谢谢。

node.js geocoding yandex-maps yandex-api
1个回答
0
投票

如果API密钥有任何问题,请联系Yandex。地图支持。问题可能出在密钥本身或您的IP /域上。只有Yandex才能确定确切原因。

如果您需要将地址解析器中的点添加到地图中,那么在JS API中使用地理编码会更容易。简单地顺序处理地址数组的元素就足够了:

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);
    });
});

如果您在Yandex地图上显示从数据中接收到的数据并遵循其他使用条款,则可以免费使用Yandex.Map API。如果必须至少满足其中一项条件,则应切换为商业许可证。在此处查看费用:https://tech.yandex.com/maps/tariffs/doc/jsapi/prices/index-docpage/

© www.soinside.com 2019 - 2024. All rights reserved.