General Searches

The sample shows how to perform a programmatic search and inspect the results.

Organizing your code

The Getting Started section details various SDK installation options depending on your requirements. The sample code below is based on a base use case of a plain html page and the ES6 module format.

Performing a search and inspecting the results

The code below shows how to perform a search for "restaurants", including requesting details for all results and then iterate over each result using the "search" command:

<!DOCTYPE html>
<html lang="en">

	<head>
		<script type="module">

			import LMInit from 'https://maps.locuslabs.com/sdk/LocusMapsSDK.js'

			const config = {
				venueId: 'lax',
				accountId: 'A11F4Y6SZRXH4X',
				headless: false
			}

			window.LMInit = LMInit
			LMInit.setLogging(true)
			LMInit.newMap('.mymap', config)
				.then(m => { 
					window.map = m;
					// Pass "true" to get POI details, else only ids are returned
					map.search("restaurant", true).then(results => {

						console.log("*** Search Results ***");
						var result;
						for (result of results) {

							console.log("Name:", result.name);
							console.log("Id:", result.poiId);
							console.log("Position:", result.position);
						}
					});
				})
				.catch(e => console.error('Error initializing map: ', e))

		</script>
		<style>
			html, body, .mymap {
				height: 100%; margin: 0; padding: 0;
			}
		</style>
	</head>

	<body>
		<div class="mymap" style="height: 100%;"></div>
	</body>

</html>

Results

The following is an extract of the console output of the above code:

Name: – "Osteria by Fabio Viviani"
Id: – "921" (63.js, line 294)
Position: – {floorId: "lax-south-departures", latitude: 33.941206, longitude: -118.401776, …} 
{floorId: "lax-south-departures", latitude: 33.941206, longitude: -118.401776, structureName: "Terminals 4-8", buildingId: "lax-south", …}Object

Name: – "Cantina Laredo"
Id: – "934" 
Position: – {floorId: "lax-tbit-baggageclaim", latitude: 33.943253, longitude: -118.408665, …}
{floorId: "lax-tbit-baggageclaim", latitude: 33.943253, longitude: -118.408665, structureName: "Terminal B", buildingId: "lax-tbit", …}Object