gpt4 book ai didi

javascript - Here-Maps Routing API 因凭据无效而失败,但其他 Here-API 继续使用完全相同的凭据

转载 作者:行者123 更新时间:2023-11-30 19:44:29 25 4
gpt4 key购买 nike

所以,我从 https://developer.here.com/documentation/maps/topics/routing.html 复制粘贴了示例代码在建立一个新的 Freemium 项目后进入一个新项目,直到最近路由 API 神秘地开始拒绝我的 API 请求时它才完美地工作:

凭据似乎没问题,因为使用它们的每个其他请求都工作得很好。我是否遗漏了什么,或者这是他们的问题?

(网站托管于 https://www.cs.drexel.edu/~nim28/CI102/Projects/Project-1/trucking-gps.php )

// Instantiate a map and platform object:
var platform = new H.service.Platform({
'app_id': '4I898D4cYJAYrLryygIZ',
'app_code': 'lfkO_XjyiIn0D-IdiPw-rg',
useHTTPS: true
});
// Retrieve the target element for the map:
var targetElement = document.getElementById('map');

// Get the default map types from the platform object:
var defaultLayers = platform.createDefaultLayers();

// Instantiate the map:
var map = new H.Map(targetElement, defaultLayers.normal.map, {
zoom: 10,
center: {
lat: 52.51,
lng: 13.4
}
});

// Create the parameters for the routing request:
var routingParameters = {
// The routing mode:
'mode': 'fastest;car', // The start point of the route:
'waypoint0': 'geo!50.1120423728813,8.68340740740811', // The end point of the route:
'waypoint1': 'geo!52.5309916298853,13.3846220493377', // To retrieve the shape of the route we choose the route
// representation mode 'display'
'representation': 'display'
};

// Define a callback function to process the routing response:
var onResult = function(result) {
var route, routeShape, startPoint, endPoint, linestring;
console.log(result);
if (result.response.route) {
// Pick the first route from the response:
route = result.response.route[0];
// Pick the route's shape:
routeShape = route.shape;

// Create a linestring to use as a point source for the route line
linestring = new H.geo.LineString();

// Push all the points in the shape into the linestring:
routeShape.forEach(function(point) {
var parts = point.split(',');
linestring.pushLatLngAlt(parts[0], parts[1]);
});

// Retrieve the mapped positions of the requested waypoints:
startPoint = route.waypoint[0].mappedPosition;
endPoint = route.waypoint[1].mappedPosition;

// Create a polyline to display the route:
var routeLine = new H.map.Polyline(linestring, {
style: {
strokeColor: 'blue',
lineWidth: 10
}
});

// Create a marker for the start point:
var startMarker = new H.map.Marker({
lat: startPoint.latitude,
lng: startPoint.longitude
});

// Create a marker for the end point:
var endMarker = new H.map.Marker({
lat: endPoint.latitude,
lng: endPoint.longitude
});

// Add the route polyline and the two markers to the map:
map.addObjects([routeLine, startMarker, endMarker]);

// Set the map's viewport to make the whole route visible:
map.setViewBounds(routeLine.getBounds());
}
};

// Get an instance of the routing service:
var router = platform.getRoutingService();

// Call calculateRoute() with the routing parameters,
// the callback and an error callback function (called if a
// communication error occurs):
router.calculateRoute(routingParameters, onResult, function(error) {
alert(error.message);
});
#map {
height: 50vh;
width: 75vh;
margin: auto;
display: block;
vertical-align: middle;
background: gray;
}

html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}


/*# sourceMappingURL=trucking-gps.css.map */
<!DOCTYPE html>
<html>

<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<script src="https://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="https://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
</head>

<body style="background:gray;">
<div id="map"></div>
</body>

</html>

编辑


顺便说一句,我确实已经将这些 key 注册到正确的域,所以这不是问题。

最佳答案

免费增值用户需要在他们的请求中设置正确的 HTTP Referer header 。检查此处日志,我们可以看到您正在使用:

referer= https://www.cs.drexel.edu/~nim28/CI102/Projects/Project-1/trucking-gps.php

但是,Delivery Portal 中的 referrer 设置为“cs.drexel.edu”(无 www)

这就是您收到 401 错误的原因。因为 app_id/app_code 正确且有效,所以出现 http 401 的唯一原因是引用错误。我们已经在本地确认将 referrer 设置为 https://cs.drexel.edu/~nim28/CI102/Projects/Project-1/trucking-gps.php确实有效。

希望这对您有所帮助!

关于javascript - Here-Maps Routing API 因凭据无效而失败,但其他 Here-API 继续使用完全相同的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55069912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com