

Now when you enter a location in the geocoder, the map view will adjust to contain both the searched location and the closest store, and will open the closest store's popup. Save your work and refresh the page in your browser. const bbox = getBbox(stores, 0, searchResult)
#DISTANCE FROM AND TO LOCATIONS CODE#
You can read more about the available parameters in the documentation on GitHub.Ĭopy the code below and paste it inside your tags, inside your map.on('load', () => ) to create a bbox using the getBbox() function you created in the last step. There are several other parameters you can specify. In this case, you'll limit the search results to the Washington DC area using the bbox parameter. Īdd the geocoder control to your JavaScript code using the constructor new mapboxgl.Geocoder. Next, set up your document by adding the Mapbox GL Geocoder plug-in and Turf.js library links to your HTML file.Ĭopy the following code and paste it inside your tags after your links to mapbox-gl.js and mapbox-gl.css.
#DISTANCE FROM AND TO LOCATIONS HOW TO#
Add Mapbox GL geocoder plugin and Turf.js Use Maptives mapping software to calculate the distance between two or more locations or points on a map Read on to learn more about how to use Maptives. Make sure you use your own access token and set it equal to mapboxgl.accessToken. Open the index.html file in a text editor. Inside you'll find an index.html file and an img folder that contains the custom marker you'll be using to show store locations. You'll see this folder referred to as your project folder.ĭownload the starter-code zip file.

Use the text editor of your choice for writing HTML, CSS, and JavaScript.įor this project, we recommend that you create a local folder called "sort-store-locator" to house your project files. Turf is an open-source analysis library that performs spatial analysis in the browser and in Node.js. The Mapbox GL Geocoder plugin is the Mapbox GL JS wrapper library for the Mapbox Geocoding API. Mapbox GL JS is a JavaScript API for building web maps. Your Mapbox access tokens are on your Account page. Create a copy of the final version of that code for this new project, or you can download the starter code here. This tutorial builds off of the code created in the Build a store locator using Mapbox GL JS tutorial. To complete this tutorial, you will need:
