Help

Get Started with GraphHopper Navigation

In our previous post we introduced the GraphHopper Navigation SDK. Today we’ll show the detailed steps on how to customize our GraphHopper Navigation demo app that uses the GraphHopper Navigation SDK.

Android Studio Installation

For Android development you need to install Android studio:

  1. Download Android Studio for your operating systen (~1GB) https://developer.android.com/studio/
  2. Install Android Studio and start it. It will download the emulator and some data like the maven repository and build tools (0.75GB). Under linux you unzip it and run: ./android-studio/bin/studio.sh &

Open Navigation Demo Project

To open the demo project click “check out from Version Control” and select git:

Use the URL

https://github.com/graphhopper/graphhopper-navigation-example.git

to clone the project:

Click “yes” to open the cloned Gradle project and then “ok” with the default settings. Android Studio now downloads Gradle automatically in the background:

After a few seconds it should be possible to browse through the source code in the “Project” tab:

Run the Navigation Demo

Find the file app/src/main/res/values/developer-config.xml and replace the gh_key and the keys for the tile style. I.e. after the edit there should not be “[YOUR_KEY]” placeholders anymore.

Now click on “Add Configuration”. Find and click the plus sign (“+”) and select “Android app”. Name it “Demo” and select “app” as Module, then click “OK”:

Click on the triangle to start it.

If you do not have an Android device connected you then create the “nexus 9” virtual device. In this process you have to download an image (0.9GB) like “Pie” before you can continue. In our experience we were able to start the app but it did strange things in the emulator so we recommend a real device instead.

To use your real device you have to enable the developer options and enable USB debugging. The latter one is device dependent and you have to look around in the web to find how to do this.

On Linux there can be a problem that you do not have access from within the IDE to the device, which is easy to fix. See some of the problems documented here.

Use the Navigation Demo

Before you can use the demo you have to enable your GPS location and allow the GraphHopper Navigation demo app to access this location information. If this was successful you should see a map with a circle highlighting your current location:

Long press somewhere on the map or search a location with the magnifier icon. It should then print a route:

Click the arrow to start the navigation:

Debug the Navigation Demo

It is easy to debug the navigation demo as you can go to the settings (gear wheel icon) and click “simulate route” and disable “start route from current location”:

Now you need to long press twice to define a route with any start location, it will then automatically go along the route and simulate the navigation.

Have fun and report any issues with this tutorial here.