我需要获取一组地址的坐标以在 Yandex 地图小部件上显示它们。有很多地址,所以我要在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 出了点问题,但无法弄清楚到底是什么。如何从 nodejs 脚本中正确获取坐标?有可能\合法吗?
谢谢你。