【发布时间】:2020-09-17 00:23:58
【问题描述】:
我在这里使用第一个示例来获取基于地址的地理坐标: https://developer.here.com/documentation/maps/3.1.15.1/dev_guide/topics/geocoding.html
我的 JavaScript 编码看起来与官方文档中的几乎相同:
var platform = new H.service.Platform({
'apikey': 'HERE IS MY API KEY'
});
// Get an instance of the geocoding service:
var service = platform.getSearchService();
service.geocode({
q: 'Berlin'
}, (result) => {
result.items.forEach((item) => {
console.log("test");
});
}, alert);
但是,当发送地理编码请求时,我收到以下错误:
Access to XMLHttpRequest at '**https://geocode.search.hereapi.com/v1/geocode?xnlp=CL_JSMv3.1.16.1&apikey=[HERE IS MY API KEY]&q=Berlin**' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
API 密钥发送正确,为什么我仍然收到 CORS 错误? 如果我在浏览器中手动输入请求 URL,我会得到响应,一切都很好。
【问题讨论】:
标签: maps geocoding here-api geocode