Text Search in Geographic Area¶
Search for places using free-form text. Obtain the results located within the given geographic area.
Setup¶
Prerequisites¶
Setting your API key token¶
To set your API key token, define it like this:
#define API_TOKEN "YOUR_API_KEY_TOKEN"
replacing YOUR_API_KEY_TOKEN
with your actual API key token text, within the quotes.
This can be done in the main()
function, before the following line:
#if defined(API_TOKEN)
or outside the main()
function, further up, or in a header file.
Although it is also possible to define your API key token as the text value of the GEM_TOKEN
environment variable, this is not recommended, as it is not secure.
Use case¶
Search for points of interest relevant to the given input text. Filter the results by a geographic area.
How to use the sample¶
When you open the sample, you’ll be viewing the scene from above. A fly will be performed to the first point of interest found.
How it works¶
Create an instance of
Environment
and set your API key token:
1int main( int argc, char** argv )
2{
3 std::string projectApiToken = "";
4#define API_TOKEN "YOUR_API_KEY_TOKEN"
5#if defined(API_TOKEN)
6 projectApiToken = std::string( API_TOKEN );
7#endif
8 // Sdk objects can be created & used below this line
9 Environment::SdkSession session(projectApiToken, { argc > 1 ? argv[1] : "" });
The SDK is initialized with your API key token string and the log file path, where to write the application logs. Note that the log file path is not initialized by default, the empty string above, after the API key token, which means that no logs are written. The log file path is initialized with the first command line argument, if any. Create a
gem::MapView
interactive map object, using an OpenGL context for 3D graphics, the SDK environment created above, and a touch event listener for interactive user touch and mouse input, such as pan and zoom.
1// Create an interactive map view
2CTouchEventListener pTouchEventListener;
3gem::StrongPointer<gem::MapView> mapView = gem::MapView::produce(session.produceOpenGLContext(
4 Environment::WindowFrameworks::Available, "SearchFreeTextLimitByGeographicArea", &pTouchEventListener));
5if ( !mapView )
6{
7 GEM_LOGE( "Error creating gem::MapView: %d", GEM_GET_API_ERROR() );
8}
Instantiate a
gem::LandmarkList
to hold the results, and aProgressListener
to be informed when the search is completed.gem::SearchService().search()
is used, passing in the landmark list to be filled in with the results, the progress listener, a text string to search for, and thegem::Coordinates()
of the point around which to search, given as latitude and longitude, in degrees. Additionally, a bounding box is passed in, containing the upper-left and the lower-right corners of a rectangle, within which to search. Each corner is specified as a latitude and longitude, in degrees.The
WAIT_UNTIL()
macro waits for the search to complete, as indicated by its progress listener, or 15 seconds (15000 msec) max.If there is at least 1 result (the results landmark list is not empty) then center the map on the rectangle containing the first result (at index 0) and show it on the map.
1// Perform the search
2gem::LandmarkList results;
3{
4 ProgressListener searchListener;
5
6 // Upper-left,lower-right bounding box given as lat,lon coordinate pairs in degrees.
7 gem::RectangleGeographicArea rgaLatLon({34.14083, -118.12958}, {34.13146, -118.12187});
8
9 // Text to search for
10 gem::SearchService().search(results, &searchListener, "Laboratory", gem::Coordinates(34.138, -118.124), gem::SearchPreferences(), rgaLatLon);
11
12 auto ret = WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &searchListener), 15000);
13}
14if ( results.size() > 0 )
15{
16 mapView->centerOnCoordinates(results[0].getCoordinates());
17 mapView->activateHighlight(results);
18}
Use the special provided macro to keep the interactive map and wait until the user closes the window.
1 WAIT_UNTIL_WINDOW_CLOSE();
2 return 0;
3}