Skip to content

Calculate Route Multi View

Calculate two routes and add them in two separate views.

Calculate Route Multi View

Use case

Calculate routes and display them in separate views.

How to use the sample

First, get an API key token, see the Getting Started guide.

Download the Maps & Navigation SDK for C++ archive file for Linux or Windows

When you open the sample, you’ll be viewing the scene from above. The screen will be split into two identical views. From each view a fly will be performed to a different calculated route.

How it works

  1. Create an instance of Environment and set your API key token:

1Environment& env = Environment::GetInstance();
4// Project API token available at:
7std::string projectApiToken = ""; //YOUR_TOKEN
  1. The SDK is initialized with your API key token string and the log file path, where to write the application logs. Note that logFilePath is not initialized by default, which means that no logs are written. The logFilePath is initialized with the first command line argument, if any.

1std::string logFilePath;
2if ( argc > 1 )
3   logFilePath = std::string(argv[1]);
5env.InitSDK( projectApiToken, logFilePath.c_str() );
  1. Create two MapViewListener objects, one OpenGLContext, one Screen and two MapView objects.

 1MapViewListenerImpl mapViewListener1;
 2MapViewListenerImpl mapViewListener2;
 4auto oglContext = env.ProduceOpenGLContext("calculateRouteMultiView");
 5gem::StrongPointer<gem::Screen> screen = gem::Screen::produce(oglContext, gem::RR_Automatic);
 6gem::StrongPointer<gem::MapView> mapView1 = gem::MapView::produce(screen, gem::RectF(0.f, 0.f, 0.5f, 1.f), &mapViewListener1);
 7gem::StrongPointer<gem::MapView> mapView2 = gem::MapView::produce(screen, gem::RectF(0.5f, 0.f, 1.f, 1.f), &mapViewListener2);
 9auto ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener1), 15000);
10auto ret2 = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener2), 15000);
  1. Create a RouteList, a ProgressListener, a LandmarkList with two Landmarks in it and a RoutePreferences object.

1gem::RouteList routes1, routes2;
3    ProgressListener calculateRouteListener;
4    gem::LandmarkList waypoints;
5    waypoints.push_back(gem::Landmark("San Francisco", { 37.77903, -122.41991 }));
6    waypoints.push_back(gem::Landmark("San Jose", { 37.33619, -121.89058 }));
7    gem::RoutePreferences preferences;
  1. Call the RoutingService using RouteList, LandmarkList, RoutePreferences and the progress listener. Wait up to 15 seconds (15000 milliseconds) for the route computation to complete.

1    gem::RoutingService().calculateRoute(routes1, waypoints, preferences, &calculateRouteListener);
2    auto ret = WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &calculateRouteListener), 15000);
  1. Perform steps 4 and 5 for the 2nd MapView.

2    ProgressListener calculateRouteListener;
3    gem::LandmarkList waypoints;
4    waypoints.push_back(gem::Landmark("London", { 51.516128, -0.142828 }));
5    waypoints.push_back(gem::Landmark("Paris", { 48.848462, 2.327315 }));
6    gem::RoutePreferences preferences;
7    gem::RoutingService().calculateRoute(routes2, waypoints, preferences, &calculateRouteListener);
8    auto ret = WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &calculateRouteListener), 15000);
  1. Once the route calculation operations complete, if the resulting route list contains at least one route for each of the 2 calculated route collections, add the first calculated route (at index 0) of each collection to their corresponding view MapViewPreferences routes collection. Instruct both MapView objects to center on the first route of its route collection.

 1if (routes1.size() > 0 && routes2.size() > 0)
 3    mapView1->preferences().routes().add(routes1[0], true);
 4    mapView1->centerOnRoute(routes1[0], gem::Rect(), gem::Animation(gem::AnimationLinear, gem::ProgressListener(), 2000));
 5    ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener1), 15000);
 7    mapView2->preferences().routes().add(routes2[0], true);
 8    mapView2->centerOnRoute(routes2[0], gem::Rect(), gem::Animation(gem::AnimationLinear, gem::ProgressListener(), 2000));
 9    ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener2), 15000);

C++ Examples

Maps SDK for C++ Examples can be downloaded or cloned with Git