使用此处地图API v3.1的新apikey,我得到了一个错误"apikey invalid. apikey not found"



我正在尝试使用Here Maps版本3.1的api,尤其是地理编码服务。

我已按照步骤获得了 api 密钥,然后尝试使用文档的示例代码访问地理编码器服务。

我用我的新 apikey 替换了{YOUR_API_KEY},并将示例代码放入一个新的索引.html文件中:

<html>
<head>
<script
src="https://js.api.here.com/v3/3.1/mapsjs-core.js"
type="text/javascript"
charset="utf-8"
></script>
<script
src="https://js.api.here.com/v3/3.1/mapsjs-service.js"
type="text/javascript"
charset="utf-8"
></script>
</head>
<body>
<div id="mapContainer"></div>
<script>
// Instantiate a map and platform object:
var platform = new H.service.Platform({
apikey: "MY_API_KEY"
});
// Retrieve the target element for the map:
var targetElement = document.getElementById("mapContainer");
// Get default map types from the platform object:
var defaultLayers = platform.createDefaultLayers();
// Instantiate the map:
var map = new H.Map(
document.getElementById("mapContainer"),
defaultLayers.vector.normal.map,
{
zoom: 10,
center: { lat: 52.51, lng: 13.4 }
}
);
// Create the parameters for the geocoding request:
var geocodingParams = {
searchText: "200 S Mathilda Ave, Sunnyvale, CA"
};
// Define a callback function to process the geocoding response:
var onResult = function(result) {
var locations = result.Response.View[0].Result,
position,
marker;
// Add a marker for each location found
for (i = 0; i < locations.length; i++) {
position = {
lat: locations[i].Location.DisplayPosition.Latitude,
lng: locations[i].Location.DisplayPosition.Longitude
};
marker = new H.map.Marker(position);
map.addObject(marker);
}
};
// Get an instance of the geocoding service:
var geocoder = platform.getGeocodingService();
// Call the geocode method with the geocoding parameters,
// the callback and an error callback function (called if a
// communication error occurs):
geocoder.geocode(geocodingParams, onResult, function(e) {
alert(e);
});
</script>
<style>
#mapContainer {
width: 100%;
height: 300px;
}
</style>
</body>
</html>

当我在浏览器中打开此文件时,我可以看到带有城市名称和所有内容的地图,因此我认为我有权访问地图 api,但地理编码服务失败并显示 401 错误:{"error":"Unauthorized","error_description":"ApiKey invalid. ApiKey not found."}

但是我的 apikey 在我的项目页面中已启用,我已经检查过并且我没有拼错 apikey(我复制/粘贴了很多次以确保)。

你有什么建议吗?

谢谢。

添加 ApiKey 时,请始终记住删除键前后的额外空格,并删除 {}。

https://developer.here.com/documentation/maps/dev_guide/topics/geocoding.html

最新更新