Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mapbox Cookbook

You're reading from   Mapbox Cookbook Over 35 recipes to design and implement uniquely styled maps using the Mapbox platform

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781784397357
Length 264 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (8) Chapters Close

Preface 1. Introduction to Mapbox FREE CHAPTER 2. Mapbox Services 3. TileMill and Mapbox Studio 4. Mapbox.js 5. Mapbox.js Advanced 6. Mapbox GL Index

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:

  1. Inside the <script> tag, begin by creating a variable for the access token, as follows:
    var accessToken = 'pk.eyJ1Ijoibmltcm9kNyIsImEiOiJkNkw1WWRnIn0.pnQn9P2nbHyhKf2FY_XJog';
  2. Then, pass the access token to Mapbox using the following code:
    L.mapbox.accessToken = accessToken;
  3. Now, get the element that holds the address box using the following code:
    var click = document.getElementById('click');
  4. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image