如何使用GraphHopperWeb在地图上查看GHResponse

时间:2015-03-20 19:10:53

标签: java graphhopper

我正在尝试使用GraphHopperWeb来查看网络上的路由响应。 我可能不知道如何使用它,但我没有得到什么是错的。 我使用以下代码(在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),(32.07006,34.79019),(32.07028,34.78867),(32.07029,34.78852),(32.07029,34.78847),(32.06994,34.78814),( 32.06942,34.78761),(32.06931,34.7875),(32.06912,34.78731),(32.06862,34.78667),(32.06756,34.78546),(32.06627,34.78391),(32.06617,34.78375),(32.06604,34.7836),(32.06622, 34.78317),(32.06768,34.78009),(32.06769,34.77998),(32.06767,34.77992),(32.06654,34.77915),(32.06624,34.77894),(32.0666,34.77764),(32.06709,34.7778),(32.06708,34.77785) ,[(0,继续到הנציב,6.186,742),(2,向右转到שדרותיהודית,164.23,19706),( - 2,向左转到מנחםבגין,2,142.253,9310),(0,继续到מנחםבגין ,517.411,31039),(2,向右转到לינקולן,394.313,28388),( - 1,向左转到יהודההלוי,183.917,13240),(2,向右转到בלפור,128.87,9278),(2 ,右转进入שדרותרוטשילד,56.539,4070),(2,右转进入המגיד,4.589,550),(4,完成!,0.0,0)]

但是当我打开地址为“http://localhost:8989/route”的资源管理器时,我收到以下错误:

{“info”:{“copyrights”:[“GraphHopper”,“OpenStreetMap contributors”],“errors”:[{“details”:“java.lang.IllegalStateException”,“message”:“至少2必须指定点,但是:0“}]}}

我不知道如何通过资源管理器在地图上看到GHResponse(我找到的路由路径)?

1 个答案:

答案 0 :(得分:0)

外部GraphHopperWeb client的使用类似于嵌入式路由described here的使用,可视化点可以通过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();