我正在尝试使用GraphHopperWeb来查看web上的路由响应。我可能不知道如何使用它,但我不明白哪里出了问题。我使用以下代码(在java中)来找到从一个点到另一个点的路径,如下所示:
GHRequest req = new GHRequest(32.070113, 34.790266, 32.067103, 34.777861).
setWeighting("fastest")
.setVehicle("car");
GraphHopperWeb gh = new GraphHopperWeb();
gh.load("http://localhost:8989/route");
gh.setInstructions(true);
GHResponse response = gh.route(req);
System.out.println(response);
我得到以下打印屏幕:
节点:24:(32.07012,34.79021)、(32.07011,34.7902 4.7836),(32.06622,34.78317),(3.206768,34.78009),(32206769,34.77998),(32.06767,34.77992),(32.06654,34.77915,[(0,继续到Şרית,6.186742),(2,右转到دררתייר,164.2319706),128.879278),(2,右拐到Ş
但当我打开带有地址的explorer时http://localhost:8989/route"我得到以下错误:
{"info":{"copyright":["GraphHopper","OpenStreetMap contributors"],"errors":[{"details":"java.lang.IllegalStateException","message":"必须指定至少2个点,但为:0"}]}}
我不知道如何通过浏览器在地图上看到GHResponse(我找到的路由路径)?
外部GraphHopperWeb客户端的使用与此处描述的嵌入式路由的使用类似,用于可视化的点可以通过getPoints获取,也可以通过getInstructions:获取转弯指令
GHRequest req = new GHRequest(32.070113, 34.790266, 32.067103, 34.777861)
.setWeighting("fastest")
.setVehicle("car");
GHResponse res = gh.route(req);
if(res.hasErrors()) {
// handle or throw exceptions res.getErrors()
return;
}
// get path geometry information (latitude, longitude and optionally elevation)
PointList pl = res.getPoints();
// distance of the full path, in meter
double distance = res.getDistance();
// time of the full path, in milliseconds
long millis = res.getTime();
// get information per turn instruction
InstructionList il = res.getInstructions();