Skip to main content
GuidesAPI ReferenceExamples

Hello Maps

Estimated reading time: 3 minutes

This complete example displays a movable and zoomable map, embedded inside an html element on a webpage.

Overview

The interactive map is centered on a desired initial location which is defined as a point using a (longitude, latitude) coordinate pair with altitude in meters. 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

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

The first step in JavaScript is to set your API key token gem.core.App.token, which you can get at the Magic Lane website, see the Getting Started tutorial. You only need to type your email address and create a new password.

let defaultAppScreen = gem.core.App.initAppScreen(
{
container: "canvasDiv",
center: [48.8612, 2.333, 1000]
}
);

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.