Skip to main content
By the end of this guide you will have a functional Store Finder that will allow you to:
  • Capture an end user’s location and convert this to co-ordinates
  • Calculate the closest stores to that end user from your Location List
  • Display those stores (and information associated with them) in a UI panel
  • Display the end user location and stores on a map
Note that this guide is specific to setting up a Store Finder using JavaScript, which is the only supported integration currently.

As mentioned above this guide focuses on using MapLibre for rendering, however other open source libraries are available for this - such as Leaflet and Tanagram.
CSS Styling

Tailwind CSS styling is used throughout this guide to minimise the need for ‘custom’ styling, however you can use whatever CSS styling you like.
We’ve broken the setup process down into a number of steps which need following in order. Those steps are:
  • Prerequisites
  • Creating the HTML for your application
  • Adding an interactive map
  • Adding geocoding
  • Displaying store information and markers
  • Attribution statement

Prerequisites

Before getting started it is essential that you understand some of the key concepts of a Store Finder and have everything set up to start building. You should:

Creating the HTML for your application

This step will cover setting the foundation of your Store Finder’s HTML, and will determine where the components we add later are placed.
  1. Create index.html
  2. Insert the following HTML, which will create the foundation for your Store Finder with a div on the right for where you map will be rendered and a div on the left for where your stores will be listed. Note that this includes a script reference for TailWind CSS to make styling easier, but you don’t need to do this if you’re using your own CSS styling.
  1. Save the file.
  2. View our additions so far.
Our initial web page

Adding an interactive map

This step covers adding in the interactive map to your page so that your end user can visualise the results of a search. We use MapLibre as a rendering library for this, but other map renderers are available.
  1. Open index.html
  2. Add the required dependencies and our Javascript entrypoint. Changes are marked within <!-- NEW --> and <!-- END --> tags.
  1. Save the file.
  2. Create index.js. In this section we cover a function to call our Map Tile API, which will return a signed URL that can be used to pull map tiles and style from Loqate. This URL is then passed into MapLibre along with a zoom level and co-ordinates of where to centre the map. If you’re setting up a Store Finder for a specific country, you could use the centre point of that country so that the map always starts there. In our example we’re setting the co-ordinates to Gloucester in the UK, and a zoom level of 16 (which is street level).
  1. Save the file.
  2. View our additions so far.
Our page with a map added

Adding geocoding

The next step is to add a way of capturing your end user’s address/postcode/city/locality and converting it into co-ordinates. Co-ordinates are required for us to do our distance calculation later in the guide. The following code will add a simple input field, a Find button to start the geocode process, and a marker to the map of where the end user is.
  1. Open index.html
  2. Add the following addition to index.html, which adds the text input field and Find button. Changes are marked within <!-- NEW --> and <!-- END --> tags.
  1. Save the file.
  2. Open index.js and add the following additions. The first code block wraps the call to our Geocoding API, while the second block is a helper function for adding markers to our map.
  1. Add the following to the main function. This adds an event handler to the Find button that will call our Geocoding API and then use the co-ordinates returned to add a marker to the map and move to that location.
  1. View what we have so far. You can type an address into the text box and click Find - the map should then update with the location you entered pinned on the map.
Displaying a location on the map

Displaying store information and markers

This next step is to retrieve the closest stores to the end user and display these in the left pane, along with markers on the map. This requires the use of a previously uploaded Location List either via our Create List API or the List Upload UI in your Account section.
  1. Open index.html and add a Store container following our Find button div.
  1. Then add the following as the last element within the body section. This determines which pieces of store information will be displayed on the page.
  1. Open index.js and add the following, which sets the parameters for the call to our Distance Finder API, taking an origin location (where your end user is), the listID of your stores and other parameters such as the max distance.
  1. Add the following to index.js to add your store information to the left pane, and add a marker representing the store to the map.
  1. Update main to the following. This will make the call to our Distance Finder API and iterate through the results to display them in the UI and on the map. Remember to Update the locationListId variable with the desired Id of the uploaded list.
  1. You can now test by entering an address in the text box and clicking Find. This will update the map with locations close to the address entered.
A working Store Finder

Attribution Statement

You must ensure attribution is visible when rendering a map as part of your application. Loqate uses map styling from OpenMapTiles and open data from OpenStreetMaps. Attribution is provided by default as part of the map style configuration, however if you choose to create your own map styling you must still ensure that this attribution is visible. For further information on copyright notices please see the Loqate Terms and Conditions.