Offline navigation

Hi~,I am new to android development & osm & graphhopper.
Now, I want to calculate routes offline , but I don not know how to do.
I have the OSM data like map.osm, and I read the guide in https://github.com/graphhopper/graphhopper/blob/master/docs/android/index.md.

It says :

Download the raw openstreetmap file - you’ll need that for the next step to create the routing data
Execute ./graphhopper.sh import . This creates the routing data
Download a map e.g. berlin.map
Copy berlin.map into the created berlin-gh folder

I use :
GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.load(“/mnt/sdcard/osmdroid/map.osm”);
But it was wrong.

I don’t understand it.If someone could tell me how to do step by step carefully,thanks a lot~

Hello Mantj,

in my understanding GraphHopper alone is not sufficient for this offline planning. The combination of Cruiser and GraphHopper seems promising in this respect (no pointer at hand presently, please dig yourself for that), but I did not get those two to cooperate when tried that some months ago. Even though I would love to have such a feature myself I stayed with online planning due to lack of necessity and the omnipresent availability of an internet connection since then.

Regards,
Petra

Thanks for your answer.
I found an app called PocketMaps in github, It is a offline app that use graphhopper to plan.
Now I follow :

this doc that I want to create data by .osm but not by mapsforge, But I get a error when I go to:

hopper.importOrLoad();

the log is :

10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: java.lang.VerifyError: com/graphhopper/reader/OSMInputFile
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.reader.OSMReader.preProcess(OSMReader.java:168)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.reader.OSMReader.readGraph(OSMReader.java:148)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.importData(GraphHopper.java:759)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.process(GraphHopper.java:725)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:698)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.example.administrator.myapplication.MainActivity$6.run(MainActivity.java:628)

Do you know what it means?Thanks a lot~

Regards,
Mantj

GraphHopper has an Android sample which you can study to check the GraphHopper API in action.

But where can one download routing files for specific areas?

I had read this code again and again,and I try again and again.Because I am new to Android development & graphhopper , I don’t know this code:

tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath() + “-gh”);

what does “currentArea” means?Does it can be named freely? And why I should plus “-gh”?

Today I saw your answer that “Routing via Java API”.So I want to get the data from osm file “.osm” without using mapforge.

I follow :

GraphHopper hopper = new GraphHopperOSM().forServer();
hopper.setOSMFile(osmFile);
hopper.setGraphHopperLocation(graphFolder);
hopper.setEncodingManager(new EncodingManager(“car”));
is OK .
BUT when I goes to :
hopper.importOrLoad();

there is an error:

10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: java.lang.VerifyError: com/graphhopper/reader/OSMInputFile
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.reader.OSMReader.preProcess(OSMReader.java:168)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.reader.OSMReader.readGraph(OSMReader.java:148)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.importData(GraphHopper.java:759)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.process(GraphHopper.java:725)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:698)
10-17 14:28:31.861 32197-774/com.example.administrator.myapplication E/AndroidRuntime: at com.example.administrator.myapplication.MainActivity$6.run(MainActivity.java:628)

What can I do?

Regards,
Mantj

I try to download the map data from openstreetmap.org , the file format is : xx.osm

Because the area I need is not so big , I want to use osm directly without using mapsforge.

You need to build the graphs, e.g. using GraphHopper script, where @karussell can answer better for any issues.

An alternate graph creator is (desktop) Cruiser application (I’m the author).

osm & pbf files are containers of OpenStreetMap data.

  • To use them with Mapsforge you need to build a .map file (we provide maps here).
  • To use them with GraphHopper you need to build a graph (folder).

Performing builds on less powerful mobile devices can be difficult, you can do it on desktop and transfer the result.

Regarding Android sample, it downloads / unzips a selected area (containing a Mapsforge map and a GraphHopper graph) and then loads them.
I suggest to invest time and study its code, it shows many things for how to use GraphHopper API.

1 Like

Thank you so much.And I have some questions:

For .map file:
i.I get the maps from the link
ii.Then I creat a graph folder by

mapsFolder = >newFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),“/graphhopper/maps/”);

iii. I renamed the map file to bj.map ,and then put it into /mnt/sdcard/graphhopper/maps/ , then use

GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.load(new File(mapsFolder, “bj”).getAbsolutePath() + “-gh”);

And there is an error.

For the .osm file:
i. I download the map file .osm and renamed it to bj.osm , then I put it into my osmdroid folder.
ii.I use:

GraphHopper hopper = new GraphHopperOSM().forMobile();
hopper.setOSMFile(/mnt/sdcard/osmdroid/bj.osm);
hopper.setGraphHopperLocation(/mnt/sdcard/graphhopper/);
hopper.setEncodingManager(new EncodingManager(“car”));

here is OK ,but when I go to :

hopper.importOrLoad();

It has an error:

com.example.administrator.myapplication E/AndroidRuntime: java.lang.VerifyError: com/graphhopper/reader/OSMInputFile

I want to know what is wrong in each step I try?Is that I lack some folder or some data?

Regards,
Mantj

Run the Android sample, download with it an area and then check in the device storage the downloaded files to understand the structure.

Mapsforge and GraphHopper are two separate libraries, which load their data in different ways (Mapsforge here and GraphHopper here).

And again, don’t try building graphs on the mobile with importOrLoad (as you’ll need many more dependencies), do it on desktop with the recommended tools and transfer the graph afterwards.

Thank you very much!
I follow your suggestion and now I can run the sample berlin.map in my project.

And now I have another question,the map of China is too large(700M+) , I just need one province map,but I can’t find the file I need(just has one file of the whole China but not province or city).
Can I create map file by myself that I can get a smaller file?

Regards,
Mantj

You have built a graph for a province only and you want a map for that area too?

You can do it, but we should discuss any map creation in Mapsforge forum. :slight_smile:

haha~ of course. However, thank you very much~

Hello,I want to download the whole china.map from used graphhopper.
but the example app has not the China map.(only berlin , bayern,hamburg,sachsen,england,new-york)
Where I can download the map?Could you please give me some suggestions or a link?

GraphHopper example uses Mapsforge maps, you can find them at their download server.

Additionally you’ll need to build a GraphHopper graph for the region you want, following the instructions in the documentation.

In the server. I can only download the .map file.
But when I want to use offline navigation in graphhopper , I can not load the .map file without the
edges file , how can I create my own edges file?

HI , I do not know
Execute ./graphhopper.sh import <your-osm-file>. This creates the routing data

This step is execute in where?Please help:sweat:

i create this using GIT. If you are using windows, you need to install Apache maven Link

@Mantj see our Android docs

(BTW: maven is installed automatically)