I am trying to create an application that integrates Osmdroid with Graphhoper to achieve autonomous routing in an urban area. I exported an osm file from Open Street Maps and converted this file to pbf. The problem is that the application does not load the pbf file because Graphhoper is trying to parse the pbf file using java.xml.stream, which is not available on Android devices. Here is the function I use to download the pbf file.
public void setRouting(){
File dir = new File(Environment.getExternalStorageDirectory(),"osmdroid");
File osmFile=new File(dir,"offline-map.osm.pbf");
if(!osmFile.exists()){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("File doesn't exist").setTitle("Error");
AlertDialog dialog = builder.create();
dialog.show();
return;
}
GraphHopper hopper = new GraphHopper().forMobile();
hopper.setEncodingManager(encodingManager);
hopper.setGraphHopperLocation(getApplicationContext().getFilesDir().getPath());
hopper.setOSMFile(osmFile.getAbsolutePath());
hopper.setCHShortcuts("fastest");
hopper.importOrLoad();
}
I know that you can convert osm to ghz (which works in my case):
https://github.com/graphhopper/graphhopper/blob/0.3/docs/android/index.md
but I can not do this:
./graphhopper.sh import <your-osm-file>
in Windows OS.
I do not use Maven to enable Graphhopper. I inserted jar into the libs folder.
osm ?
.
:
- Apache maven
- - Windows maven.
- Enviroment MAVEN_HOME, ..: C:\Program Files\Apache Software Foundation\apache-maven-3.2.1. ( , M2_HOME)
- Clone Graphopper git git zip -
- Cygwin
- Cygwin
- $cd/cygdrive/
- "ls", .
- Graphhopper git root.
.. c:\git\graphopper:
$ cd c
$ cd git
$ cd graphhoper
. Linux
10. filename.osm Graphhoper git root
11. $./graphhopper.sh import filename.osm
12. filename-gh Graphopper git, , .
13. .
14. - :
` dir = new File (Environment.getExternalStorageDirectory(), "map-parent-folder-name" ); ghDir = (dir.getAbsolutePath(), "filename-gh" );
hopper = new GraphHopper().forMobile();
hopper.setCHShortcuts("fastest");
hopper.load(ghDir.getAbsolutePath());
init graphopper
. Graphopper (graphhopper-0.3-SNAPSHOT.jar), :
$ ./graphhopper.sh build filename.osm
jar core/target/folder
trove-3.0.3.jar, . trove-3.0.3.jar zip libs .
, :)