Skip to content

Simulated Navigation

In this guide you will learn how to compute a route between a departure and destination, and render the route on an interactive map, supporting pan and zoom. The map will be centered on the route such that the route fits in the viewport.
Next, navigation is simulated along the route.

Prerequisites

Before starting this guide, it is required that you complete the following guides:

Compute a route

Open the file CenterMap.cpp and add the following includes:

1#include <API/GEM_NavigationListener.h>
2#include <API/GEM_NavigationService.h>
Add the code below after the mapView->centerOnRoute() call:
1WAIT_TIME_OUT(2000);
2gem::NavigationListener navlistener;
3ProgressListener navProgressListener;
4gem::NavigationService().startSimulation(routes[0], navlistener, &navProgressListener);
5WAIT_TIME_OUT(2000);
6mapView->startFollowingPosition(gem::Animation(gem::AnimationLinear, gem::ProgressListener(), 2000));
This waits 2 seconds (2000 msec) after the camera flew to the route and centered it in the viewport, and then starts the navigation simulation.
Another 2 seconds pause is inserted, so that a nice fly from the route overview to the following position mode can occur, where the camera follows the green arrow as it travels along the route, simulating navigation.

Try it out!

vstudio navigation - example CPP screenshot

Click the green arrow play button at the top to compile and run the project.
After the route is computed and rendered on the map, you can pan the map and zoom in/out using the mouse scroll wheel.
Note that panning the map during the simulation will stop the camera from following the green arrow. To start following the green arrow (position) again, call mapView->restoreFollowingPosition()