Question

I thought this would be a pretty simple thing to do given I have the lat / lng stored in a Geofield. However, I'm really struggling.

Basically I just want to show the 20 nearest nodes to the current node in a block.

No address fields or anything complicated, just straightforward coordinates...

Any ideas before I start hacking?!

BTW, I'm a relative Drupal newbie, but lots of PHP experience.

Thanks, Chris

Was it helpful?

Solution 2

My solution:

  • In the contextual filter field add a Geofield proximity filter - something like "Content: Location (field_location) - proximity". Set the radius distance at the bottom.
  • Under "When the filter value is NOT available" select "PHP Code"
  • Enter the following PHP. The return value is the argument that is passed to the filter.
    $node = menu_get_object();
    $value = field_get_items('node', $node, 'field_location');
    $lat = $value[0]['lat'];
    $lon= $value[0]['lon'];
    return ($lat . ', ' . $lon);

Figured this out from this page https://drupal.org/node/2014345

OTHER TIPS

First install the excellent location module.

Add location fields to your results content type and to your main content type.

Create a view based on the main content type (I presume you have this installed) and show as a block.

In the view open advanced filters and in the contextual filters add a filter for "location distance/proximity" is the closest 20 results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top