因此,在设置新的Freemium项目之后,我将示例代码从https://developer.here.com/documentation/maps/topics/routing.html复制粘贴到了新项目中,并且直到最近路由API神秘地开始拒绝我的API请求为止,它都可以正常工作:{{ 3}}
鉴于使用这些凭据的每个其他请求都可以正常工作,因此凭据似乎还可以。我是否缺少某些东西,或者这是他们的问题?
// 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>
我做将那些密钥注册到正确的域btw,所以这不是问题。
答案 0 :(得分:1)
免费增值用户需要在其请求中设置正确的HTTP Referer标头。检查此处日志,我们可以看到您正在使用:
referer = https://www.cs.drexel.edu/~nim28/CI102/Projects/Project-1/trucking-gps.php
但是,Delivery Portal中的引荐来源网址设置为“ cs.drexel.edu”(无www)
这就是为什么您会收到401错误的原因。因为app_id / app_code是正确且活动的,所以HTTP 401的唯一原因是错误的引荐来源网址。我们已经在本地确认将引荐来源网址设置为https://cs.drexel.edu/~nim28/CI102/Projects/Project-1/trucking-gps.php确实可行。
希望这会有所帮助!