[英]HERE maps for JavaScript API: How to calculate route?
I wanna implement in my project option to draw route on the map using HERE maps api, I read documentation and saw few examples and if I implement it all global and push static route to calculate distance like that:我想在我的项目选项中实现使用 HERE maps api 在地图上绘制路线,我阅读了文档并看到了几个例子,如果我实现它全部全局并推送静态路线来计算这样的距离:
const platform = configPlatform();
const defaultLayers = configLayers();
var markers = [];
var map = new H.Map(
document.getElementById('mapContainer'),
defaultLayers.vector.normal.map,
{
zoom: 10,
}
);
var mapEvents = new H.mapevents.MapEvents(map);
var behavior = new H.mapevents.Behavior(mapEvents);
var icon = setCustomMarker();
const lineString = new H.geo.LineString();
var polyline;
var routingService = platform.getRoutingService();
var routingParameters = {
'mode': 'fastest;car',
'waypoint0': 'geo!50.1120423728813,8.68340740740811',
'waypoint1': 'geo!52.5309916298853,13.3846220493377',
'representation': 'display'
};
routingService.calculateRoute(routingParameters, success => {
console.log(success);
});
It works fine, but I wanna do everything in functions (instantiate platform must be global and it's ok).它工作正常,但我想在函数中做所有事情(实例化平台必须是全球性的,没关系)。 First of all I wanna by navigator configure center of map (current user position) and next by event listener give user possibility to add markers to map and it all works but if I wanna next push data to routing service and calculate route between markers and whole distance I get following error:
首先,我想通过导航器配置地图中心(当前用户位置),然后通过事件侦听器让用户可以向地图添加标记,这一切正常,但是如果我想接下来将数据推送到路由服务并计算标记和整体之间的路线距离我得到以下错误:
Uncaught (in promise) TypeError: c is not a function at eval(eval at (mapsjs-core.js:70), :64:238)
Uncaught (in promise) TypeError: c is not a function at eval(eval at (mapsjs-core.js:70), :64:238)
Even if I just call method routingService.calculateRoute() inside eventlistener I get the same error.It looks like something in calculateRoute function must be instantiate in time map loading because it works ok when I calculateRoute next to loading map but if I use that function I listener It doesn't work.即使我只是在 eventlistener 中调用方法 routingService.calculateRoute() 我也会得到同样的错误。看起来calculateRoute 函数中的某些东西必须在加载时间地图时实例化,因为当我在加载地图旁边计算时它可以正常工作,但是如果我使用该函数我听它不起作用。 Somebody had any idea how to make it possible to run this method in listener (instantiate globally routing service doesn't help) ??
有人知道如何在侦听器中运行此方法(实例化全局路由服务无济于事)??
I tried your code with little update in calculateRoute callback and all worked perfectly:我在calculateRoute回调中尝试了很少更新的代码,并且一切正常:
routingService.calculateRoute(routingParameters, success => {
console.log(success);
});
If the problem persists, please attach a link to simple working example with this issue.如果问题仍然存在,请附上指向此问题的简单工作示例的链接。
Recently I created simple jsfiddle example for adding routing waypoints on contextmenu
(right-click) event callback, maybe it could also help you.最近,我创建了简单的jsfiddle用于添加路由航点例如
contextmenu
(右键单击)事件回调,也许它也可以帮助你。
And I configure that the externals libs weren't problem.我配置外部库没有问题。 I could run the same code page without any custom code of twig and assets and one page deployed on lamp server works properly.
我可以在没有任何树枝和资产的自定义代码的情况下运行相同的代码页,并且部署在灯服务器上的一个页面可以正常工作。 Second one identical copy deployed on symfony server still had error in js console
在 symfony 服务器上部署的第二个相同副本在 js 控制台中仍然有错误
Uncaught (in promise) TypeError: c is not a function at eval(eval at (mapsjs-core.js:70),"
Uncaught (in promise) TypeError: c is not a function at eval(eval at (mapsjs-core.js:70),"
If I try read error after reject by console log I get:如果我在被控制台日志拒绝后尝试读取错误,我会得到:
Error: [] https://route.ls.hereapi.com/routing/7.2/calculateroute.json?xnlp=CL_JSMv3.1.12.0&apikey=(my api key here)=fastest%3Bcar&waypoint0=geo!50.1120423728813%2C8.68340740740811&waypoint1=geo!52.5309916298853%2C13.3846220493377&representation=dragNDrop request failed at eval (eval at (mapsjs-core.js:70)
错误:[] https://route.ls.hereapi.com/routing/7.2/calculateroute.json?xnlp=CL_JSMv3.1.12.0&apikey=(我的api key在这里)=fastest%3Bcar&waypoint0=geo!50.1120423728813%2C871073%2C871073way =geo!52.5309916298853%2C13.3846220493377&representation=dragNDrop 请求在 eval 失败(eval at (mapsjs-core.js:70)
When I click into link I had a lot of numbers and on the end distance so the error response looks for me like success response.当我点击链接时,我有很多数字,并且在最后距离上,因此错误响应看起来像成功响应。 That's realy odd for me.
这对我来说真的很奇怪。 I thought symfony server cannot ingerate in js on client side.
我认为 symfony 服务器无法在客户端的 js 中集成。 Someone had any possibilities what is wrong ??
有人有任何可能性有什么问题吗??
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.