我为此苦苦挣扎了一段时间,所以我有两个问题要问。
第一个问题:我无法更改开放路线服务的配置文件。当我在下面的代码中输入 api-key 时,我的代码正在工作。
var control;
function tests() {
var control = L.Routing.control({
waypoints: [
L.latLng(coords),
L.latLng(coords2)
],
router: new L.Routing.openrouteservice('Api-Key'),
}).addTo(map);
document.getElementById("RouteButton").onclick = tests;
};
但是当我尝试更改配置文件时,它要么不会更改,要么会收到错误消息。
到目前为止我尝试过的事情是。
router: new L.Routing.openrouteservice({api_key:'HIDDEN', profile:'footwalking'),
和
router: new L.Routing.openrouteservice('https:// api.openrouteservice.org /directions? & api_key = Hidden& profile = foot-walking'),
第一个有效,但配置文件没有改变它仍然使用驾驶汽车默认配置文件。
第二个给了我两条错误消息,
第一条错误消息是 | 访问“ https://api.openrouteservice.org/directions ”上的 XMLHttpRequest ?来自原点“ http://localhost:8000 ”的 CORS 策略已阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。|
第二条错误信息 | corslite.js:87 获取https://api.openrouteservice.org/directions?403(禁止)|
两条错误消息都给出了一个长网址,我将其缩短为https://api.openrouteservice.org/directions ?。
我得到的另一个问题是,我如何清除地图,以便在绘制新路线时删除先前绘制的路线。在下面的图片中,您可以看到当我请求第二条路线时会发生什么,包括我显示的旧路线和新路线。
希望大家能帮忙。