Finding an address on a map click
Now that we are learning to construct a GET request using Mapbox services, it's time to apply our knowledge in a real application.
We will use a simple JavaScript with Mapbox.js to make our lives easier. Don't worry about Mapbox.js; we have an entire chapter dedicated to it.
How to do it…
Perform the following steps for this:
- Inside the
<script>
tag, begin by creating a variable for the access token, as follows:var accessToken = 'pk.eyJ1Ijoibmltcm9kNyIsImEiOiJkNkw1WWRnIn0.pnQn9P2nbHyhKf2FY_XJog';
- Then, pass the access token to Mapbox using the following code:
L.mapbox.accessToken = accessToken;
- Now, get the element that holds the address box using the following code:
var click = document.getElementById('click');
- Next, create a Mapbox
map
object and pass the initial coordinates and the zoom level by executing the following code:var map = L.mapbox.map('map', 'nimrod7.k4adg5mg').setView([51.492842, -0.131874...