Skip to main content
GuidesAPI ReferenceExamples

Search POI Categories Near a Location

Estimated reading time: 4 minutes

Search for POIs (Points of Interest) by categories around a specified location. Click on a category from the left side list to view the POIs highlighted on the map and the interactive results list on the right side of the map.

Overview

The map supports pan and zoom, and is fully 3D, so holding down the shift key and panning will simultaneously rotate and tilt the map.

See the example fullscreen

If you want to jump right in, you can download the HTML file and the JavaScript file for this example in the same directory, and then load the HTML file in a web browser to try it out right now! Or you can continue reading for a detailed explanation of the code.

 // Start by setting your token from https://developer.magiclane.com/api/projects
if (gem.core.App.token === undefined)
gem.core.App.token = "";

var defaultAppScreen = gem.core.App.initAppScreen({
container: 'map-canvas',
center: [48.207825, 16.371557, 5000], // latitude , longitude, altitude
});

let poiListCallback = function (parentDiv, resultedLandmarkItem) {
parentDiv.className = 'card';
parentDiv.style = 'width:100%';
let whatToAdd = '<div class="card-body">' +
'<h5 class="card-title">' + resultedLandmarkItem.getName() + '</h5>' +
'<h6 class="card-subtitle mb-2 text-muted">' + resultedLandmarkItem.getAddress() + '</h6>' +
'<p class="card-text">' + resultedLandmarkItem.getDescription() + '</p>' + '</div>';
parentDiv.innerHTML = whatToAdd;
}

var poiControl = new gem.control.POICategoryListControl({
container: 'poi-category'
});
let nearbyControl = new gem.control.SearchNearbyControl({
categorylistcontrol: poiControl,
populateItemFunction: poiListCallback
});

defaultAppScreen.addControl(nearbyControl);
defaultAppScreen.addControl(poiControl);

The example is 2 plain text files, one with the HTML code ( .html file extension) and the other with the JavaScript code ( .js file extension).
To run the example, the HTML file is loaded in a browser. The .js file should be in the same directory, as it will be loaded automatically.

Source code for this example:

Right-click on the links and select Save As.

JavaScript Examples

Maps SDK for JavaScript Examples can be downloaded or cloned with Git