GraphHopper.com | Forum | GitHub | Maps | Blog

How to get Route info offline (like time, distance,turns)


#1

I want to develop App that using graph-hopper offline map with routing, I am using https://github.com/mapsforge/mapsforge code to do this. Now I am facing a challenge to get offline right, left turn information with time and distance left to reach the destination.


#2

You can use the instructions, see our documentation.


#3

Thank you @karussell for the reply, But for this API I have to put my device online to get JSON data. Please tell me how I get all this information offline (when device not connected to the internet)


#4

See my recent answer here: Graphhopper java library to travel time calculation


#5

Modified the question, please check:


#6

@karussell Please give answer here: Graphhopper java library to travel time calculation
@karussell Please give the solution, Is there has any way to get navigation information offline?


#7

@karussell Please tell us if you have any solution. How we can get route information turn by turn offline.


#8

You can check routing documentation.
The returned route instructions contain various info, like sign, distance, time, etc.


#9

@devemux86 thanks for reply but inside GHResponse I am getting following response:-

respone: ; nodes:34; (52.50455783023791,13.4177302700245), (52.504962738714276,13.4180209804629), (52.50503705825739,13.41809883903188), (52.505067791903045,13.41825343858272), (52.505071889722466,13.418383264952524), (52.50508138921294,13.418594302652648), (52.50510690745205,13.41872226637726), (52.50515347358182,13.41885302406966), (52.50529186811951,13.419018426962609), (52.50576535252702,13.41934029205159), (52.50540623453423,13.420621791942905), (52.50521773484091,13.421293089269692), (52.50515365984634,13.421584220713024), (52.50510262336811,13.421980964138678), (52.505091820026,13.422116564708574), (52.50506332155459,13.422509210314807), (52.505055125915746,13.42328760974007), (52.50509237881956,13.423895390865848), (52.505204510060054,13.42470471020128), (52.505277898280575,13.425052466058414), (52.50537028548204,13.425398918063914), (52.505508121226164,13.4258301204256), (52.50568041590632,13.426271939864872), (52.50579645870171,13.426507750746035), (52.505851034205804,13.426619323192968), (52.50599557547261,13.42691473872024), (52.506250385334724,13.427290247990719), (52.506366614394636,13.427431436496185), (52.50643888502804,13.427521029729865), (52.506637256740866,13.42772796961057), (52.50725286097645,13.428195679817998), (52.50735307128772,13.428258823489967), (52.50730576009987,13.428381758072565), (52.507227294260474,13.428572169662974), [(0,Leuschnerdamm,188.44109359877166,27135), (2,Bethaniendamm,732.825,58623), (2,Köpenicker Straße, L 1066,25.406685420961367,2032), (4,0.0,0)]

My code is like :-

public void calcPath(final double fromLat, final double fromLon, final double toLat, final double toLon) {

    log("calculating path ...");
    new AsyncTask<Void, Void, PathWrapper>() {
        float time;

        protected PathWrapper doInBackground(Void... v) {
            StopWatch sw = new StopWatch().start();
            GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).setAlgorithm(Algorithms.DIJKSTRA_BI);
            req.getHints().put(Routing.INSTRUCTIONS, true);
            GHResponse resp = hopper.route(req);
            Log.d("respone_ok",resp.toString());
            time = sw.stop().getSeconds();
            return resp.getBest();
        }

        protected void onPostExecute(PathWrapper resp) {
            if (!resp.hasErrors()) {

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

#10

If you’re using Java code, the documentation shows how to iterate over every turn instruction and get its properties:

// use the best path, see the GHResponse class for more possibilities.
PathWrapper path = rsp.getBest();

// points, distance in meters and time in millis of the full path
PointList pointList = path.getPoints();
double distance = path.getDistance();
long timeInMs = path.getTime();

InstructionList il = path.getInstructions();
// iterate over every turn instruction
for(Instruction instruction : il) {
   instruction.getDistance();
   ...
}

#11

Thank You @devemux86 I move one step forward, I am getting following response:-

[(0,WaldemarstraĂźe,224.8471772752855,32377), (-2,AdalbertstraĂźe,225.28199999999998,18021), (2,Bethaniendamm,511.30054040571883,40902), (4,0.0,0)]

actually in this response we know turn information:-

public static final int LEAVE_ROUNDABOUT = -6;
public static final int TURN_SHARP_LEFT = -3;
public static final int TURN_LEFT = -2;
public static final int TURN_SLIGHT_LEFT = -1;
public static final int CONTINUE_ON_STREET = 0;
public static final int TURN_SLIGHT_RIGHT = 1;
public static final int TURN_RIGHT = 2;
public static final int TURN_SHARP_RIGHT = 3;
public static final int FINISH = 4;
public static final int REACHED_VIA = 5;
public static final int USE_ROUNDABOUT = 6;

but don’t know where it is, we need lat-long with this indications.


#12

You can check the Instruction various getters.
They return the sign, description, first lat,lon, point list, distance and time, etc.

Can see also InstructionList.createJson for all them in action.


#13

@devemux86
I want information where is turn on the map (we need latitude, longitude) for that turn. You can see in the image latitude, longitude help to point exactly where is turn on the map.

expected JSON:-

[(0,WaldemarstraĂźe,224.8471772752855,32377,latitude, longitude), (-2,AdalbertstraĂźe,225.28199999999998,18021,latitude, longitude), (2,Bethaniendamm,511.30054040571883,40902,latitude, longitude), (4,0.0,0,latitude, longitude)]


#14

How do you use GraphHopper?

If use via Java code, I mentioned above how to get instruction properties, like their coordinates.

If use via website Json then Peter mentioned also the documentation.

In any case you need to remember to have the instructions generation enabled.


#15

@devemux86
I am using This code same.Like mention in this link.


#16

@devemux86
I appreciate if you give me quick response because my project delivery time is passed. Please suggest me what next should I do to resolve this problem.


#17

@devemux86 @karussell
Please tell me if there is any update regarding my problem. I am still waiting


#18

There is mentioned above how to enable instructions and when getting the response how to iterate them and retrieve their properties.

Where exactly is the issue with those guides?
And don’t be confused with json, it’s not required in offline graphs, can work with regular Java API.


#19

actually iam also developing a project for offline map can you guide me


#20

Please read this thread carefully and invest a bit time into research :slight_smile: