The following solution works:
- Get the graphhopper project in your IDE.
- Get the raw Openstreetmap data (.pbf) via this very nice provider.
- Run this command in your (git) bash shell: ./graphhopper.sh -a import -i gelderland-latest.osm.pbf
Make a new (maven) project with this pom.xml file:
nl.xyz
graphhopper
1.0
system
${project.basedir}/libs/graphhopper-web-1.0-SNAPSHOT.jar
Copy generated graphhopper-web-1.0-SNAPSHOT.jar from the graphhopper project to the libs folder of your new project so it will be included in your path.
Copy the generated graphhopper data to a folder within your small project.
Create this simple demo:
public static void main(String[] args) {
private static String mapsFolder = "graphhopper-data/yourlocation-latest.osm-gh";
GraphHopper graphHopper = new GraphHopper().forMobile();
graphHopper.load(mapsFolder);
System.out.println("Found graph " + graphHopper.getGraphHopperStorage().toString() + ", nodes:" + graphHopper.getGraphHopperStorage().getNodes());
QueryResult queryResult = graphHopper.getLocationIndex().findClosest( 52.11111, 6.111111, EdgeFilter.ALL_EDGES);
double distance = queryResult.getQueryDistance();
System.out.println( "Shortest distance is: " + distance);
}
UPDATE: Using the JAR on Android may give a lot of compiler errors due to library version mismatchers. A better solution for getting this example run at Android, is using this dependency in your build.gradle:
implementation 'com.graphhopper:graphhopper-core:1.0-pre33'
Consequence is that you have to set the default routing profile. You can achieve via this change:
graphHopper = new GraphHopper().forMobile();
// Next line:
graphHopper.setProfiles( Collections.singletonList(new ProfileConfig("my_car").setVehicle("car").setWeighting("fastest")));
graphHopper.load(routingDataFolder);
I hope you enjoy this wonderful 'graphhopper' software!