这个问题的解决方案是什么"failed to load resource: net::ERR_CONNECTION_REFUSED http://localhost:8989/route?....."



我的程序有问题。这是一个关于地理信息系统的程序,使用了LeatlefJs库,我还使用了左侧路由机的功能。问题是系统不能显示它应该显示的路线,我真的不明白。这是脚本。

function getDirectRoute(index, callbackFunction){
var dari = marker_awal.getLatLng().lat + "," + marker_awal.getLatLng().lng;
var tujuan = markerCabang[index].getLatLng().lat + "," + markerCabang[index].getLatLng().lng;
$.ajax({
type: "GET",
url: "http://localhost:8989/route?point=" + dari + "&point=" + tujuan + "&points_encoded=false&instructions=false&vehicle=motorcycle&ch.disable=true&weighting=shortest&algorithm=alternative_route",
dataType: 'json',
contentType: "application/json",
success: function (data) {
successReveived++;
var coordinates = data.paths[0].points.coordinates;
tempDistance = 0;      
for(var j=0; j<coordinates.length; j++){
if(j==0){
tempDistance += euclidean(marker_awal.getLatLng().lat, marker_awal.getLatLng().lng, coordinates[j][1], coordinates[j][0]);
} else {
tempDistance += euclidean(coordinates[j-1][1], coordinates[j-1][0], coordinates[j][1], coordinates[j][0]);
}
}
distanceGH[index] = data.paths[0].distance;
distanceManual[index] = tempDistance.toFixed(4);

if(successReveived == markerCabang.length && typeof(callbackFunction == 'function')){
callbackFunction();
}
}
});
} 

错误如下

加载资源失败:net::ERR_CONNECTION_REFUSED http://localhost:8989/route?point=3.611967691620835,98.67254734039308&point=3.611126,98.67548&points_encoded=false&instructions=false&vehicle=motorcycle&ch.disable=true&weighting=shortest&algorithm=alternative_route

(我还不能评论,所以试着帮你回答)

  1. 确保你有一个有效的后端来响应JS库(见https://www.liedman.net/leaflet-routing-machine/tutorials/alternative-routers/有效的后端)
  2. 尝试直接在浏览器中输入URL(没有传单或其他任何东西):http://localhost:8989/route ->您应该看到JSON输出,即使它说的是格式错误或无效的请求。如果你在这里已经有网络问题,你需要检查网络层(例如防火墙,后端端口绑定等),如果不是这种情况,继续。
  3. 在浏览器的DEV工具(F12)中打开网络选项卡,过滤所有到后端的连接。现在尝试map/leafletJS并检查该选项卡中的其他信息。你可能会看到一个错误,你的浏览器阻止了请求,由于一些相关的跨源请求(CORS)。

最新更新