Skip to content

Center Map

Center the map view over a pair of coordinates.

Center Map

Use case

Present a given area of the world map in a window.

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 map view will move over the given set of coordinates.

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 a MapViewListener, OpenGLContext and MapView.

2    MapViewListenerImpl listener;
3    auto oglContext = env.ProduceOpenGLContext("centerMap");
4    gem::StrongPointer<gem::MapView> mapView = gem::MapView::produce(oglContext, &listener);
  1. Instruct the MapView to center on desired coordinates.

1    mapView->centerOnCoordinates({ 37.768741, -122.482696 }, 60);
  1. Allow the application to run until the map view is fully loaded, with a 15 second (15000 millisecond) timeout. Then continue waiting until the user closes the map view window.

1    auto ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &listener), 15000);

C++ Examples

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