Hi,

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 suggestions - so I can go to bed tonight?!

Thanks,
Chris

Comments

surfgatinho’s picture

Any suggestions?

surfgatinho’s picture

OK, this is how far I have got.

I can now get the required list of nearby nodes, BUT only if I enter the coordinates for the filter criteria manually using a geofield-proximity field.

I suppose the question now becomes how do I get the geofield values from my node into the sort filter?

surfgatinho’s picture

Fixed it.

Slightly underwhelmed by the response here. Can't believe no one has ever done this before, yet here I am a month into hardcore Drupaling and I had to....

Just posted my solution below:

Jaypan’s picture

If you'll look, this topic comes up regularly on Drupal, and I've never actually seen someone have a response. So you aren't the first person to try, but few have been able to do it.

I've got a tutorial on the matter in my list of tutorials to write, but I also have about 300 other things on my list to do, and this is my busiest time of year for work, so you'll have to be patient for a few more months for a solution from me (it's more than I can write into a forum thread, as it's dynamic and I don't want to be answering support questions on the matter in a thread).

Hopefully someone else will come along with a solution in the meantime.

pixelsweatshop’s picture

Fixed it.

if you fixed it. Don't just say "fixed it!" and move on. Take the time to write out the steps because there will literally be hundreds of other users that will come across this thread in the future and will hit a dead end because you failed to report back. If you want help, you also need to help.

Slightly underwhelmed by the response here. Can't believe no one has ever done this before, yet here I am a month into hardcore Drupaling and I had to....

There are very few users that actually help out in the forums on a regular basis. It's not that other haven't run across this issue. It's that the ones that have are off doing something else (or as Jaypan is) to busy to write out step by step how to accomplish this in a forum thread. Blaming the community for not helping you is not going to get you very far here.

WorldFallz’s picture

Blaming the community for not helping you is not going to get you very far here.

Particularly when that same user then responds 'Fixed it' without elaborating. that certainly puts them on my 'do not help' list. sheesh.

surfgatinho’s picture

Was intending to post this at some point, so here is what I got working for me:

* 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);

* Last step (optional) might be to sort in order of proximity (use contextual geofield proximity...)

What helped, but didn't actually answer my scenario was this post: drupal.org/node/2014345

Please note, this may not work with a views page as the filter is available. In this case the code may be used to set the arguments handler (or something like that?!)

If there is a better way of doing this I'd love to hear about it

DrCord’s picture

This worked well, tyvm!

3dnathaniel’s picture

This did not work for me. Getting error 500 when trying to use this.

surfgatinho’s picture

I did recently update this code as it threw ajax errors when editing it in views. New (improved code) is:

if($node = menu_get_object()){

$value = field_get_items('node', $node, 'field_location');
$lat = $value[0]['lat'];
$lon= $value[0]['lon'];

return ($lat . ', ' . $lon);
}

Give that a go...

3dnathaniel’s picture

Works! Thank you!