Create a block view for node pages that displays nearby nodes based on location

Last updated on
30 April 2025

This example shows how to create a block view for node pages that displays other nodes (not including the currently viewed node) that are nearby (based on location proximity).

To create the view (this assumes basic views knowledge):

  1. Create a view of type Node.
  2. Select Fields for the Row style setting (you can use any row style that suits your requirements).
  3. Add any Fields you want for you view (this example uses the Node: Title field).
  4. Add the Node: Nid argument with the following settings (Note: This will not show the node currently being viewed. If you want that node included use the Global: Null argument instead, which will still use the following settings where available.):
    • Title: This can be anything you like. For this example it is left blank.
    • Breadcrumb: This can be anything you like. For this example it is left blank.
    • Wildcard: This can be anything you like. For this example it is left as all.
    • Wildcard title: This can be anything you like. For this example it is left as All.
    • Action to take if argument is not present: Provide default argument. This is required for arguments from the url to work with blocks.
    • Default argument type: Node ID from URL. This will get the nid from the url on node pages.
    • Validator: <Basic validation>. If you want to restrict this to only accept nid arguments for certain node types you can select the Node validator.
    • Action to take if argument does not validate: Hide view / Page not found (404). This will mean that the block will not display if you aren't on a node page.
    • Allow multiple terms per argument: Unchecked
    • Exclude the argument: Checked. This means that the node that is being viewed won't be in the results. If you leave this unchecked your view will only show the node you are viewing.
  5. Add the Location: Distance / Proximity filter with the following settings:
    • Operator: Choose what type of proximity search you want. This example uses Proximity (Circular).
    • Origin: Node's Latitude / Longitude from views nid argument.
    • Node ID argument to use: Select one of the arguments from the view to get the nid from. In this example it is Node:Nid.
    • Location to use: Select whether you want to use the node's node location or a CCK location field from the node. This example uses Node location.
    • Distance: Enter a numeric distance that you want to limit the results to. Also, select whether your distance is in miles or kilometres. In this example it is 100 miles.
  6. You can then add any sorts you like. This example uses the Location: Distance / Proximity sort and gives it the following settings so that the closest nodes are first:
    • Origin: Use Distance / Proximity filter.
    • Sort order: Ascending

Then assign your view block to the node pages you want it on.

I have also attached a text file containing an export of my example view to use as an easier starting point if you desire.

Help improve this page

Page status: Not set

You can: