How To Create Drupal Views Distance Filter using Location module

| Drupal Development | 95 seen

Drupal is a popular content management system that allows users to create complex websites with a wide range of features and functions. One of the most useful features of Drupal is its ability to create views, which are customizable displays of content that can be filtered and sorted in a variety of ways.

One useful type of filter is the distance filter, which allows users to filter content based on their proximity to a particular location. In this article, we will explore how to create a Drupal views distance filter using the Location module.

Drupal Distance Block

Drupal Distance Block

As you can see in above screen - I have listed Nearby Tourism sights in right sidebar displaying thumbnail, title, distance and category.

If you are looking for similiar functionality, here is what you will need:

  • Drupal
  • Views module
  • Location module
  • Gmap  module (recommended)

Enable Location module to be able collect geo data, be sure you enable it for your content type as well. You might want to use Gmap module as well for displaying geo data on Google Maps.

Now once you have some content type with Location enabled, and you have entered a few nodes with location information, you can create a "Nearby locations" view:

Drupal views: Nearby Locations

Drupal views: Nearby Locations

As you can see this is pretty basic Drupal view - though to make it work, you will need to pay attention to Contextual Filters, Filter Criteria and Sort Criteria.

Contextual Filters

Content:Nid

  • Provide default value: Content ID from URL

Under More tab:

  • Check next to Exclude

Drupal Contextual Filters

Drupal Contextual Filters

Filter Criteria:

Add a new filter: Location: Distance/Proximity

  • Origin: Node's Latitude / Longitude from views nid argument
  • Node ID argument to use: Content Nid

Drupal views distance filter

Drupal views distance filter

Sort Criteria

Add a new criteria: Location / Proximity (asc)

  • Change order of sort, so Location / Proximity filter is first of order

Now save your view and add a newly created block to your theme. 

Creating a Drupal views distance filter using the Location module is a useful way to allow users to filter content based on their proximity to a particular location. By following the steps outlined in this article, you can easily create a Drupal view with a location filter that meets the needs of your website or application.

Alternatively, consider hiring me as your Drupal website developer.

 

Latest articles

LEGOLAND Berlin Review: A Fun Family Activity in the German Capital

When planning a family trip to Berlin with children, most travelers immediately think about the Berlin Zoo — and rightly so. But if you are spending a few days in the German capital with younger kids, another solid half-day activity is the LEGOLAND Discovery Centre BerlinWe visited it in April 2026 together with our 7-year-old daughter during our…

Germany |

Ādģēri: The 30K Mistake That Turned Into a Long-Term Experiment

In 2023, we bought Ādģēri in an online auction.Price: just over €30,000.Financing: ~6% interest.Total expected payment over ~5 years: ~€40,000.Status (April 2026): more than half already paid.On paper, it was a bad deal.Realistically, we overpaid by at least 5–6× relative to what the property was objectively worth at the time. No serious buyer…

Ādģēri |