6th Dec '25
/
0 comments

Location-based Distance Filtering on a Google Map in Bricks

Updated on 7 Dec 2025

This Pro tutorial provides detailed instructions to set up Bricks' Map element with additional location-based distance filtering or proximity search input.

We shall create a custom shortcode for showing the location input field and distance dropdown.

[posts_map_filter unit="km" default="50" options="1,3,5,10,25,50,100,250"]

unit can be km or mi.

Clicking the crosshair/target icon asks user for their permission to use their location and when granted, fills their address in the input field.

Below that is the standard Bricks search filter so visitors can quickly filter the posts by their titles or content.

The list of posts (of Location CPT, can be of any post type) will be shown using a Bricks' Posts query loop in a fixed-height column with a gradient overlay indicating the visitor that there are more underneath.

[optional] Hovering on the post title will show 'View details on the map' tooltip. This is done using BricksExtras' Popovers / Tooltips.

Clicking a post title will open the info window for that post on the map.

The address for each location post is set using ACF's Google Map field.

We have full control on what appears inside the info window when the red marker is clicked anytime or when a post is clicked and the info window opens on the map to show that post's address. This is set in a Bricks template of the type Popup.

In this tutorial, we shall show the post title, values of phone number and opening hours custom fields and a read more button that links to the post's permalink.

Input fields can be reset at any time by clicking the Reset button. We shall also trigger it when text inside the proximity input is cleared.

Step 1

Get your Google Maps API key if you don't already have one. Doc

Paste your Google Maps: API key at Bricks → Settings → API keys and save settings.

Step 2

Create your CPT (optional, the standard posts can also be used) and the corresponding ACF field group.

Step 3

Create some posts of your post type and populate the ACF fields, especially the address.

Step 4

Create a Bricks template of the type Popup named say "Map info box".

JSON of the Container (select all the text, copy and paste in Bricks editor)

Step 5

If the Bricks child theme is not active, upload it and make it active. This can be done even if the site is live.

Create a directory named assets in your child theme directory.

Create a directory named js in the above directory.

Create a filed named posts-map-filter.js in the above directory having the following code:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Filtering ACF Repeater Bricks Query Loop by Sub Field Value

Filtering ACF Repeater Bricks Query Loop by Sub Field Value

We look into how ACF Repeater rows output by a Bricks query loop can be filtered using the bricks/query/run PHP filter.
Categories:
Pro
Conditionally Hiding Bricks Filters based on Select Filter Value

Conditionally Hiding Bricks Filters based on Select Filter Value

How show or hide Bricks' filter based on the selection made by another filter.
Categories:
Tags:
Pro
ACF Relationship Select Filter in Bricks

ACF Relationship Select Filter in Bricks

In the BricksLabs Facebook group, a user asks: I'm learning about ACF relationships and attempting to output a list of posts on any given page,…
Categories:
Pro
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories:
Pro
Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

This Pro tutorial covers how posts of a Bricks query loop can be filtered to show only the ones whose true / false or checkbox…
Categories:
Tags:
Pro
ACF Relationship: Show all other events related to the artists of the current event

ACF Relationship: Show all other events related to the artists of the current event

How all other events related to the artists of the current event can be output in a Bricks query loop.
Categories:
Pro
Sorting ACF Relationship Posts by Date Meta in Bricks

Sorting ACF Relationship Posts by Date Meta in Bricks

Consider the following setup: CPT: Events ACF Fields:Event Date Information (Group)|__Event Date (Date Picker)Pick Sub Events (Relationship) An Event can have 1 or more related…
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…