0

我从 Git(Graphhopper) 克隆了示例应用程序。
然后下载一些地图。
但是在我的应用程序中,它需要有一个选项,您可以步行或
在路线中使用自行车。
然后我在示例应用程序代码中进行了此配置。

 void loadGraphStorage() {
        new GHAsyncTask<Void, Void, Path>() {
            protected Path saveDoInBackground(Void... v) throws Exception {
                GraphHopper tmpHopp = new GraphHopper().forMobile();
                tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath());
                hopper = tmpHopp;
                return null;
            }

            protected void onPostExecute(Path o) {
                if (hasError()) {
                    err = "An error happend while creating graph:" + getErrorMessage();
                } else {
                    err = "Finished loading graph. Press long to define where to start and end the route.";
                }
                finishPrepare();
            }
        }.execute();
    }

和这里。

 public void calcPath(final double fromLat, final double fromLon,
                         final double toLat, final double toLon) {
        new AsyncTask<Void, Void, GHResponse>() {
            float time;

            protected GHResponse doInBackground(Void... v) {
                StopWatch sw = new StopWatch().start();
                GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon);
                req.setAlgorithm(AlgorithmOptions.DIJKSTRA_BI);
                req.setVehicle("bike");
                req.getHints().put("instructions", "false");
                req.setWeighting("fastest");
                GHResponse resp = hopper.route(req);
                time = sw.stop().getSeconds();
                return resp;
            }

            protected void onPostExecute(GHResponse resp) {
                if (!resp.hasErrors()) {
                    log("from:" + fromLat + "," + fromLon + " to:" + toLat + ","
                            + toLon + " found path with distance:" + resp.getDistance()
                            / 1000f + ", nodes:" + resp.getPoints().getSize() + ", time:"
                            + time + " " + resp.getDebugInfo());
                    logUser("the route is " + (int) (resp.getDistance() / 100) / 10f
                            + "km long, time:" + resp.getTime() / 60000f + "min, debug:" + time);

                    mapView.getLayerManager().getLayers().add(createPolyline(resp));
                    //mapView.redraw();
                } else {
                    logUser("Error:" + resp.getErrors());
                }
                shortestPathRunning = false;
            }
        }.execute();
    }

我使用 setVehicle 骑自行车,但错误消息只给了我支持 Car。

4

0 回答 0