Skip to content

Search POI Categories Near a Location

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.

How it works

 1// Start by setting your token from https://developer.generalmagic.com/api/projects
 2if (gem.core.App.token === undefined)
 3    gem.core.App.token = "";
 4
 5var defaultAppScreen = gem.core.App.initAppScreen({
 6    container: 'map-canvas',
 7    center: [48.207825, 16.371557, 5000], // latitude , longitude, altitude
 8});
 9
10let poiListCallback = function (parentDiv, resultedLandmarkItem) {
11    parentDiv.className = 'card';
12    parentDiv.style = 'width:100%';
13    let whatToAdd = '<div class="card-body">' +
14        '<h5 class="card-title">' + resultedLandmarkItem.getName() + '</h5>' +
15        '<h6 class="card-subtitle mb-2 text-muted">' + resultedLandmarkItem.getAddress() + '</h6>' +
16        '<p class="card-text">' + resultedLandmarkItem.getDescription() + '</p>' + '</div>';
17    parentDiv.innerHTML = whatToAdd;
18}
19
20var poiControl = new gem.control.POICategoryListControl({
21    container: 'poi-category'
22});
23let nearbyControl = new gem.control.SearchNearbyControl({
24    categorylistcontrol: poiControl,
25    populateItemFunction: poiListCallback
26});
27
28defaultAppScreen.addControl(nearbyControl);
29defaultAppScreen.addControl(poiControl);
 1<html>
 2<meta charset="utf-8">
 3
 4<head>
 5  <meta name="viewport" content="width=device-width, initial-scale=1">
 6  <title>Search Nearby Control - GeneralMagic Maps SDK for JavaScript</title>
 7  <link rel="stylesheet" type="text/css" href="https://www.generalmagic.com/sdk/js/gem.css">
 8  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
 9    integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
10  <style>
11    .body {
12        width: 100%;
13        height: 100%;
14    }
15
16    ::-webkit-scrollbar {
17      width: 4px;
18    }
19
20    /* Track */
21    ::-webkit-scrollbar-track {
22      box-shadow: inset 0 0 5px grey;
23      border-radius: 10px;
24    }
25
26    /* Handle */
27    ::-webkit-scrollbar-thumb {
28      background: green;
29      border-radius: 10px;
30    }
31
32    /* Handle on hover */
33    ::-webkit-scrollbar-thumb:hover {
34      background: #b30000;
35    }
36
37    .carousel-control-prev-icon,
38    .carousel-control-next-icon {
39      height: 100px;
40      width: 100px;
41      background-size: 100%, 100%;
42      background-image: none;
43    }
44
45    .carousel-control-next-icon:after {
46      content: '>';
47      font-size: 55px;
48      color: green;
49    }
50
51    .carousel-control-prev-icon:after {
52      content: '<';
53      font-size: 55px;
54      color: green;
55    }
56
57    .card:hover {
58      background-color:#ffed91;
59    }
60
61    .card.active {
62      background-color: gold;
63    }
64
65    #poi-category {
66      font-size: 14px;
67    }
68  </style>
69  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
70    integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
71  </script>
72  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
73    integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
74  </script>
75  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
76    integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
77  </script>
78</head>
79<div id="map-canvas" style="width: 100%; height: 100%; position: absolute; overflow: hidden;">
80</div>
81<div id="poi-category" class="gem-markers-menu"
82  style="position: absolute; left: 0px; top: 10px; width: 10%; overflow: auto; height: 95%;">
83</div>
84</div>
85<script type="text/javascript" src="https://www.generalmagic.com/sdk/js/gemapi.js"></script>
86<script type="text/javascript" src="token.js"></script>
87<script type="text/javascript" src="searchNearbyControl.js"></script>
88
89</html>
The map-canvas is the drawing area where the map is rendered. The canvas is configured to fill the browser window.
Note that the div elements must be defined before loading the JavaScript source.
The circular-loader is the rotating circle animation seen while loading.
At the bottom, gemapi.js, the Maps SDK for JavaScript is loaded.
Next, the JavaScript source of this example is loaded.
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:

HTML and JavaScript

right-click on the links and select Save As.

JavaScript Examples

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