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();
public MatrixResult calculateMatrixOneByOne(GHPoint[] points) { int n = points.length; MatrixResult ret = new MatrixResult(n); for (int fromIndex = 0; fromIndex < n; fromIndex++) { // Loop over TO in reverse order so the first A-B we process doesn't have the same // location for FROM and TO - this makes it quicker to debug as the first call is no longer a 'dummy' one. for (int toIndex = n - 1; toIndex >= 0; toIndex--) { GHPoint from = points[fromIndex]; GHPoint to = points[toIndex]; GHResponse rsp = getResponse(from, to); if (rsp == null) { continue; } ret.setDistanceMetres(fromIndex, toIndex, rsp.getDistance()); ret.setTimeMilliseconds(fromIndex, toIndex, rsp.getTime()); } } return ret; }