Here api 尝试使用此处地图路由服务时出现未经验证的错误
我使用api v3.1,并试图计算两点之间的距离Here api 尝试使用此处地图路由服务时出现未经验证的错误,here-api,Here Api,我使用api v3.1,并试图计算两点之间的距离 var platform = new H.service.Platform({ 'apikey': 'api_key' }); //you can remove this if you dont want to see the map. var maptypes = platform.createDefaultLayers(); var map = new H.Map( document.getElementById('mapContainer
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
这就是我所拥有的
<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>
var platform = new H.service.Platform({
'apikey': 'key'
})
const params = {
mode: 'car;',
waypoint0: lat1 + ',' + lon1,
waypoint1: lat2 + ',' + lon2,
representation: 'display',
routeAttributes: 'summary'
}
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary)
}, error => {
console.log(error)
})
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
我用域白名单试过了,没有你能试着执行这段代码吗
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
希望这对你有帮助 您的apikey肯定有问题。要么是无效,要么是插入方式不正确
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
我用我的apikey尝试了你的代码,看起来不错(只需用你自己的apikey值替换“你的apikey\u字符串”):
var platform = new H.service.Platform({
'apikey': 'api_key'
});
//you can remove this if you dont want to see the map.
var maptypes = platform.createDefaultLayers();
var map = new H.Map(
document.getElementById('mapContainer'),
maptypes.vector.normal.map,
{
zoom: 10,
center: { lng: 13.4, lat: 52.51 }
});
// Till here
const params = {
mode: 'fastest;car',
waypoint0: '52.5160,13.3779',
waypoint1: '52.5206,13.3862',
representation: 'display',
routeAttributes: 'summary'
}
function calcuateRouteFromAtoB(platform){
var routingService = platform.getRoutingService()
routingService.calculateRoute(params, success => {
console.log(success.response.route[0].summary);
}, error => {
console.log(error);
})
}
calcuateRouteFromAtoB(platform);
似乎未正确传递应用程序id和应用程序密钥。“apikey”是否同时保存应用程序id和应用程序密钥?仅保存api密钥。我遵循了这个
https://developer.here.com/documentation/maps/dev_guide/topics/routing.html
而且它没有说任何关于应用程序id的内容。谢谢。它现在可以工作了,但我在每个语句中使用它时仍然有问题。我有来自用户浏览器的第一对坐标,然后我有一个需要计算距离的项目列表。实际错误是这错误:[] https://route.ls.hereapi.com/routing/7.2/calculateroute.json?xnlp=CL_JSMv3.1.8.1&apikey=api&mode=fastest%3Bcar&waypoint0=44.4512086%2C26.133909799999998&waypoint1=36.416807%2C28.146558&representation=display&routeAttributes=summary 请求在eval时失败(eval at(mapsjs core.js:66),:63:181)
如果我尝试此操作,它将不起作用window.navigator.geolocation.getCurrentPosition(函数(pos){console.log('coord')var lat=Number(pos.coords.latitude)var lon=Number(pos.coords.longitude)const params={模式:'faster;car',航路点0:'44.4512086,26.1339097999998',航路点1:'36.416807,28.146558',表示:'display',routeAttributes:'summary'}console.log(params)calcuateRouteFromAtoB(params)})
到底什么不起作用?我现在有点不知所措。你可能会共享你的页面吗?项目还没有启动。如果我调用函数从浏览器getCurrentPosition函数计算,我会得到错误:[] https://route.ls.hereapi.com/routing/7.2/calculateroute.json?xnlp=CL_JSMv3.1.8.1&apikey=api&mode=fastest%3Bcar&waypoint0=44.4512086%2C26.133909799999998&waypoint1=36.416807%2C28.146558&representation=display&routeAttributes=summary 请求在eval时失败(eval at(mapsjs core.js:66),:63:181)
但是如果我在任何自定义函数之外调用它,它会工作,但这是不同的错误,对吗?最初的问题是关于未经授权的错误。这个问题已经解决了吗?