Road Routing with GraphHopper and Java on Raspberry Pi
Join the DZone community and get the full member experience.Join For Free
graphhopper is a fast and open source routing engine written in java. the sources are at github and you can try it online . some months ago java itself was ported to raspberry pi (arm) and the latest versions even have the jdk from oracle preinstalled . so there is no reason to not trying graphhopper on raspberry pi as this week my device arrived! i was using noobs and installed raspbian where the jdk from oracle and git-core were already installed. if you have an older release do:
sudo apt-get install oracle-java7-jdk
now the graphhopper setup itself is done with 4 easy steps:
- git clone https://github.com/graphhopper/graphhopper/
# avoid the "-server" option and reduce the default memory usage for graphhopper. e.g. for berlin you can do:
export java_opts="-xmx100m -xms100m"; cd graphhopper
./graphhopper.sh import europe_germany_berlin.pbf
# this will take a bit and if it is finished you'll see "[info] started jetty server"
# under the hood it will do:
# 1. get maven
# 2. compile graphhopper (takes 10min!?)
# 3. install a smaller area 'berlin' (6min for import, 5min for ch preparation). you can avoid this if you create the graphhopper files on your desktop which is a lot faster and then copy them to your raspberry pi via scp -r europe_germany_berlin-gh pi@raspberrypi:/home/pi/graphhopper/
# 4. start a server at localhost:8989
now you can access the started server via your browser e.g. from raspberry pi itself with iceweasel or chromium-browser
if this doesn't work try http://localhost:8989/ or connect pi to your lan and access graphhopper web from your desktop via the same url.
here is a screenshot - via tiles from lyrk :
raspberry pi has less limitations compared to android!
- you have a jdk 7 from oracle, not the dalvik thing which supports java 5 only. so you can do even the graphhopper file creation ("import") directly on the mobile machine although this will be slower (factor 5-10) compared to my laptop. also you can out of the box start and use a server on the machine. sharing graphhopper routing on android is currently no out-of-the-box-solution but one should be able to make it working too.
- you have a fully working debian distribution with nice 'apt-get' capabilities
- you can use all the available ram and not only the 32mb which is a limitation per app on android. so routing will be faster because until the 500mb (limit on raspberry pi) you can use the in-memory settings of graphhopper or if using the slower mmap setting then raspberry pi will load more data into the ram compared to android.
- on android you can have offline maps via the mapsforge project. you couldn't do the same for raspberry pi but there is now a branch called 'rescue' which enables you to have offline maps for raspberry pi. this branch already works, but is not yet released.
- for full maps you will need a separate monitor - e.g. this here? and address search which is currently only possible via online service.
orginal post at karussell.wordpress.com
Opinions expressed by DZone contributors are their own.