I am using OsmDroid to build map offline and achieve turn by turn navigation along with voice over instruction which I believe could be achievable by GRAPHHOPPER library version 9.0.
So these are my steps to achieve the task
01 . Generate graph-cache file via area.osm.pbf.
02 . As I am using graph hopper version 9.0 so I am using graph hopper version 9.0 to generate graph cache which is being generated successfully.
03 . Now when I try to run this code it give error profile config mismatch even profile is there for car only provided by graph hopper version 9.0 example config.
private class LoadGraphHopperTask extends AsyncTask<Void, Void, GraphHopper> {
@Override
protected GraphHopper doInBackground(Void... params) {
try {
File graphCacheDir = new File(getFilesDir(), "graph-cache");
// Step 1: Copy graph from assets if not already copied
if (!graphCacheDir.exists() || graphCacheDir.list() == null || Objects.requireNonNull(graphCacheDir.list()).length == 0) {
copyAssetsFolder(getApplicationContext(), "map/graph-cache", graphCacheDir.getAbsolutePath());
}
// Step 2: Load GraphHopper from internal storage
GraphHopper hopper = new GraphHopper();
hopper.setGraphHopperLocation(graphCacheDir.getAbsolutePath());
Profile carProfile = new Profile("car")
.setName("car"); // Or load actual car.json if needed
hopper.setProfiles(carProfile);
hopper.load(); // Load from graph-cache
return hopper;
} catch (Exception e) {
Log.e("GraphHopper", "Error loading GraphHopper data", e);
return null;
}
}
@Override
protected void onPostExecute(GraphHopper hopper) {
if (hopper != null) {
// Calculate route now
GeoPoint start = new GeoPoint(33.6844, 73.0479); // Example: Islamabad
GeoPoint end = new GeoPoint(33.7380, 72.9998); // Example: Near Islamabad
drawGraphHopperRoute(hopper, start, end);
}
}
}