Center Map¶
Center the map view over a pair of coordinates.

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 WindowsWhen 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¶
Create an instance of
Environment
and set your API key token:
1Environment& env = Environment::GetInstance();
2
3//
4// Project API token available at:
5// https://developer.magiclane.com/api/projects
6//
7std::string projectApiToken = ""; //YOUR_TOKEN
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]);
4
5env.InitSDK( projectApiToken, logFilePath.c_str() );
Create a
MapViewListener
,OpenGLContext
andMapView
.
1{
2 MapViewListenerImpl listener;
3 auto oglContext = env.ProduceOpenGLContext("centerMap");
4 gem::StrongPointer<gem::MapView> mapView = gem::MapView::produce(oglContext, &listener);
Instruct the
MapView
to center on desired coordinates.
1 mapView->centerOnCoordinates({ 37.768741, -122.482696 }, 60);
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);
2 WAIT_UNTIL_WINDOW_CLOSE();
3}
4env.ReleaseSDK();