Integration graphhopper in android with mapforge

hi guys am samii brhane and am android developer. i just started a new project … it is food delivery app and i search github and other blogs on how to integrate graphhopper library in android but i coud’nt find any simple and clean method so help.

i have a folder with
edges, properties, geometry, nodes, names, location_index, node_ch_fastest_car,shortcuts_fastest_car
in my asset folder
so how to use these files with graphhopper to find a route between to point in a map?

1 Like

does this help?

https://www.graphhopper.com/android/

hi lars … thanks for the reply.
i have integrated the graphhopper dependence in android studio from the integration in github but what i don understand is that what file does graphhopper library need for routing
i have eritrea.map , eritrea.osm, and eritrea.osm.pbf files
using cmd graphhopper web jar created catch file like nodes and other files. so how do i use these file in android studio for routing using graphhopper …

Hiya,
I use .map with mapsforge, this displays the background map.
.osm is OpenStreetMap data, I don’t use but I think this is used to create the pbf? I just download from geofabrik.
.pbf is what graphopper will use to generate your
edges, properties, geometry, nodes, names, location_index, node_ch_fastest_car,shortcuts_fastest_car files.

Depending on your use, set .pbf file and also your processed edges etc folder.
If it can’t find your processed files folder it will create new ones from your pbf.

So to update your files, clear or delete your processed files, point to your new pbf file and have it recreate them.

Then you can assign your start and end lat long points, and return distance, time and path details from your files.

I havent used android but have setup as standalone Java project

1 Like

GraphHopper cannot work with Android scoped storage,
which requires file streams and not file paths.

GraphHopper focus now seems to be the online routing:

An Android GraphHopper sample with Mapsforge / VTM exists here:

Thanks Gregws , ur the best. u just cleared the path for me.

hi gregws … i hv done what u told me and i got some errors like this:

2021-09-09 13:51:40.975 31050-31050/com.gmail.samiibrhane.foodorder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gmail.samiibrhane.foodorder, PID: 31050
java.lang.RuntimeException: To avoid reading partial data we need to obtain the read lock but it failed. In /storage/emulated/0/foodorder
    at com.graphhopper.GraphHopper.load(GraphHopper.java:865)
    at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:706)
    at com.gmail.samiibrhane.masterapp.MapActivity.getDirections(MapActivity.java:328)
    at com.gmail.samiibrhane.masterapp.MapActivity.access$100(MapActivity.java:68)
    at com.gmail.samiibrhane.masterapp.MapActivity$1.onTap(MapActivity.java:140)
    at org.mapsforge.map.android.input.TouchGestureHandler.onSingleTapConfirmed(TouchGestureHandler.java:265)
    at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:345)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
 Caused by: java.io.FileNotFoundException: /storage/emulated/0/foodorder/gh.lock: open failed: EACCES (Permission denied)
    at libcore.io.IoBridge.open(IoBridge.java:496)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
    at com.graphhopper.storage.NativeFSLockFactory$NativeLock.tryLock(NativeFSLockFactory.java:116)
    at com.graphhopper.GraphHopper.load(GraphHopper.java:864)
    at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:706) 
    at com.gmail.samiibrhane.masterapp.MapActivity.getDirections(MapActivity.java:328) 
    at com.gmail.samiibrhane.masterapp.MapActivity.access$100(MapActivity.java:68) 
    at com.gmail.samiibrhane.masterapp.MapActivity$1.onTap(MapActivity.java:140) 
    at org.mapsforge.map.android.input.TouchGestureHandler.onSingleTapConfirmed(TouchGestureHandler.java:265) 
    at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:345) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:8167) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 
 Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8044)
    at libcore.io.IoBridge.open(IoBridge.java:482)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289) 
    at com.graphhopper.storage.NativeFSLockFactory$NativeLock.tryLock(NativeFSLockFactory.java:116) 
    at com.graphhopper.GraphHopper.load(GraphHopper.java:864) 
    at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:706) 
    at com.gmail.samiibrhane.masterapp.MapActivity.getDirections(MapActivity.java:328) 
    at com.gmail.samiibrhane.masterapp.MapActivity.access$100(MapActivity.java:68) 
    at com.gmail.samiibrhane.masterapp.MapActivity$1.onTap(MapActivity.java:140) 
    at org.mapsforge.map.android.input.TouchGestureHandler.onSingleTapConfirmed(TouchGestureHandler.java:265) 
    at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:345) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:8167) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 

so give me some code guide

Sorry my dude, I coded for desktop, unsure about android implementation.
Can you share your code?

I have to make this more precise: our focus always was the JVM. The Android VM is not a proper JVM (Google introduced this mess which they called “Java”). And the result is that the routing with GraphHopper surely and easily works offline e.g. on a Desktop. Only for mobile offline routing additional work might be necessary if there is no proper JVM. Furthermore GraphHopper still works on some old and all recent Android VMs. And the community can verify and contribute changes that this still works for future Android versions.

And regarding “GraphHopper cannot work with Android scoped storage” this is true at the moment, but others made GraphHopper working with streams which, due to its offheap nature, might work for the Android use case too, but this wasn’t tested nor contributed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.