How To Create Drupal Views Distance Filter using Location module

Updated: 29 June, 2021 seen 6,907

In this article I will show how one (perhaps you) can build a Drupal views distance filter by using Drupal,  Views and  Location.

To better ilustriate what I'm talking - take a loot at this screenshot bellow:

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


  • 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. 

You can see a live example of this functionality here:


If you have any questions related on how to build a Drupal views distance filter, please feel free to drop a comment.


About Location module

The Location module allows real-world geographic locations to be associated with Drupal nodes, including people, places, and other content. The Location module allows admins to collect addresses, geocode them (translate addresses to lattitude/longitude), and associate locations with Drupal nodes and users. Location data is automatically used to generate GeoRSS within your existing RSS feeds.

At present, it is the only module that provides the views integration necessary for implementing location-based searches and is designed for the purpose of finding points on a map within a vicinity of a user-supplied location.  If you are interested in the presentation and manipulation of geographic data beyond points (e.g., lines, polygons, etc) I would recommend using the geofield and open layers modules.

About Gmap Module

The GMap module provides an interface to the Google Maps API within Drupal. It integrates with the Location module to provide users a clickable map for entering latitude and longitude, as well as to display maps of Drupal nodes and users. GMap can be used to create interactive maps with various map markers and content in map bubbles, taking advantage of Drupal's other content management features. The module also provides a Views display plugin which allows users to display the results of a view on a Google map.