Skip to main content
This tutorial walks you through creating a web store locator that helps users find your nearest locations. We’ll build a map that centers on the user’s location, displays store markers, and includes search functionality with distance calculations.

Features used

Getting started

If you haven’t already, sign up for Radar to get your API key. Then add the Radar SDK to your application.

With npm or yarn

Install the core SDK along with the maps and autocomplete plugins:
Then import and register the plugins in your project:

With HTML

Add the core SDK and plugin scripts to your HTML file:
The plugin CDN bundles auto-register with the core SDK when loaded. Then, initialize the Radar SDK:

Create a map

Once the SDK is installed, you can render a Radar Map. The map serves as the foundation for your store locator, providing an interactive interface for users to explore store locations. Specify the HTML element where you want to render the map by providing the element’s ID or the element object itself. For more options to configure a map, see our Maps documentation. Store Locator Step1 Jpe

Add a custom map style

Radar Maps Studio allows you to create fully customizable maps for your store locator. This tool enables you to select custom styles, fonts, colors, and more, all within the Radar dashboard. Follow this tutorial to create a custom map style. Add this style to your code as shown below. SCR 20251110 Ihsg Jpe

Center the map with IP geocoding

Use Radar’s IP geocode API to localize the store locator to the user’s city without requesting location permissions. Below is sample code to call the API. SCR 20251106 Iqrk Pn
Use the coordinates returned to center the map:
The map now automatically centers on the user’s city, making nearby stores immediately visible.

Add markers and popups to the map

Populate your map with markers to show the locations of each store. You’ll need a data source with your store coordinates and information like name and address. Each marker can include a popup that displays when users click on it, showing detailed store information. This provides users with quick access to the necessary details for visiting a location. SCR 20251106 Pgcw Pn
The Radar autocomplete component allows users to search for addresses and locations, making it easy to find stores near a specific place.

Integrating with a sidebar

For an existing store locator, the autocomplete component fits naturally at the top of this sidebar as a search input. If this store locator is net-new, consider adding a simple container positioned beside or overlaying your map where you display the store list and autocomplete search. A typical layout structure looks like this:
Add the autocomplete component using the example below. SCR 20251106 Pkso Pn

Recenter the map based on user searches

When a user searches for and selects a location, recenter the map to their selection. This creates a responsive experience where the search interface and map work together seamlessly. Update the onSelection callback to recenter the map. The flyTo method provides a smooth transition.

Calculate and display distances to stores

Show users how far each store is from the map’s center point using Radar’s matrix API. The distance calculations help users quickly identify their most convenient option. Set the map center as the origins value and pass the list of store locations as the destinations value as a pipe-delimited string. Reference our matrix API documentation for additional information. Once calculated, display these distance values in your sidebar next to each store. Make sure to recalculate distances as the map center changes. SCR 20251107 Kztz Pn

Putting it all together

You now have a fully functional store locator with location detection, interactive markers, address search, and real-time distance calculations. Users can find their nearest stores in seconds without granting location permissions.