[GraphHopper] GH 0.1 -> 0.1.1 code update

Peter K peathal at yahoo.de
Sat Oct 5 09:41:25 UTC 2013


Hi Andy,

the exception is a bit misleading and I will fix this to show the real
problem.

You have to use importOrLoad instead of load otherwise there won't be
files to use for graphhopper. Also you should set the encoding manager
BEFORE calling importOrLoad, there are cases where you don't need to
specify it but setting it afterwards is wrong (I'll implement also a fix
to avoid those problems). For some good and bad examples have a look
into GraphHopperTest.

Regards,
Peter.

> Hello!
>
> I would like to use GH for measuring distance in my offline desktop
> app. Long time ago I used some 0.1 snaphot and wrote this little piece
> of code:
>
>         double fromLat = 50.216493, fromLon = 15.814353, toLat =
> 50.105043, toLon = 14.389708;
>
>         GraphHopperAPI gh = new GraphHopper().setInMemory(true, true);
>         gh.load("C:\\OSM\\streets.osm");
>         GHRequest request = new GHRequest(fromLat,fromLon,toLat,toLon);
>         request.algorithm("astar");
>         GHResponse response = gh.route(request);
>
>         System.out.println("Distance: " + response.distance());
>
> And it worked! But now i would like to use snaphot 0.1.1
> (https://oss.sonatype.org/content/groups/public/com/graphhopper/graphhopper-parent/).
> I reworked the code like this:
>
>         double fromLat = 50.216493, fromLon = 15.814353, toLat =
> 50.105043, toLon = 14.389708;
>
>         GraphHopper gh = new
> GraphHopper().forDesktop().setInMemory(true, true);
>         gh.setOSMFile("C:\\OSM\\streets.osm");
>         gh.load("C:\\OSM\\");
>         EncodingManager ecn = new EncodingManager("CAR");
>         gh.setEncodingManager(ecn);
>         GHRequest request = new GHRequest(fromLat,fromLon,toLat,toLon);
>         GHResponse response = gh.route(request);
>
>         System.out.println("Distance: " + response.getDistance());
>
> I guess it´s awfully wrong, because it´s not working (I am getting
> null pointer ex in gh.route()). Can you help me fix this please?
>
> Andy
>
>
> _______________________________________________
> GraphHopper mailing list
> GraphHopper at openstreetmap.org
> https://lists.openstreetmap.org/listinfo/graphhopper
>




More information about the GraphHopper mailing list