I tried to test offline routing with PBF file in android studio. I read this link https://osm2po.de/ and tried this code:
public class Main implements Configurer {
final static String LOGLEVEL = "debug";
public void configure(Props props) {
props.setProperty("log.0.level", LOGLEVEL);
props.setProperty("postp.0.class", PgRoutingWriter.class.getName());
}
public static void main(String[] args) {
// Lets drop the args above and simulate a commandline call with hard coded ones
args = new String[] {
"http://download.geofabrik.de/europe/germany/hamburg-latest.osm.pbf",
"tileSize=x", "prefix=hh", "cmd=cg", "workDir=work",
};
// This Main implements Configurer, which let's us overwrite other stuff via code
// see configure(Props) above
args = ArrayUtils.stringArrayConcat(
args, new String[] {"configurer.class=" + Main.class.getName()});
// The magic begins
de.cm.osm2po.Main.main(args);
// Done. Now lets check the generated Graph
Graph graph = new Graph(new File("work/hh_2po.gph"));
System.out.println("Graph Loaded. ID=" + graph.getGraphId());
// Somewhere in Hamburg
int sourceId = graph.findClosestVertexId(53.55f, 10.05f);
int targetId = graph.findClosestVertexId(53.44f, 10.15f);
// And call a simple route
int [] path = newRouter(VertexRouter.class, graph, Log.stdout())
.findShortestPath(sourceId, targetId);
if (path != null) { // Found!
for (int i = 0; i < path.length; i++) {
RoutingResultSegment rrs = graph.lookupSegment(path[i]);
int segId = rrs.getId();
int from = rrs.getSourceId();
int to = rrs.getTargetId();
String segName = rrs.getName().toString();
System.out.println(from + "-" + to + " " + segId + "/" + path[i] + " " + segName);
}
} else {
System.err.println("Sorry, route could not be found");
}
graph.close();
}
}
But I could not solve it. I want select a PBF file from sdcard in android phone and routing with custom lat, long. Please help me. What is the solution?
1