Looks like an excellent module. Before I delve too deeply, it would be nice to know if this is possible. I am using the geocoder, geofield, and addressfield modules, and have created a view with an exposed filter for proximity which lists nodes by distance from a city. It's modeled after this: https://drupal.org/node/1944648.

That works well. However I also need a "preset" view, so to speak, where the view uses the page URL rather than user input as the starting point for the search. For example, the page http://mydomain.com/city/state should show all content with addresses in that city and state.

What I need is a contextual filter for proximity, but none is currently available. Can this be accomplished with Views Global Filter?

Comments

rdeboer’s picture

Hi John,

Thanks for the reference to https://drupal.org/node/1944648, I hadn't seen that yet. May update it in light of the following.

A contextual filter for proximity has recently become available for Geofield 7.x-2.x here: #2014345: Geofield plugin for Contextual Proximity Filter (includes screenshots)
As you can read from that issue it works well with Global Filter 7.x-1.x-dev.

You may be able to tweak your solution to fit the above. Global Filter doesn't suport Addressfield as such, but it does support Geofield proximity.

But maybe you don't need Global Filter for your solution and perhaps #2011340: Geofield plugin to extend proximity filtering based on postal address with option to use HTML5 location suffices for your purpose?

Rik

johnhorning’s picture

Thanks for your quick reply. If I am correctly understanding the two patches you refer to, the first would work for a url like www.yoursite.com/yourview/lat,lon. The second does not rely on arguments in the URL, but will use the user's current location if no value is entered for the starting location. Is this correct?

If so, and if I need to base the view off of the URL, then the first patch is my best option except that I'd have to convert city/state to latitude,longitude.

Is that a correct assessment?

John

rdeboer’s picture

Yes, spot on, John
The first (contextual filter for Geofield) would also work for the extended format www.yoursite.com/yourview/lat,lon_distance.
And it defaults to the user's location if lat,lon aren't provided.

There may be options to implement URLs like www.yoursite.com/yourview/state/city. If that's a must, let me know adn we may be able to work something out.

Rik

rdeboer’s picture

Re #3 and the original request
In my replies I was focusing on Geofield a bit too much as I still had that on the brain after I'd done the patch...

But actually...

As you already have Addressfield installed you could add through the Views UI a couple Contextual Filters for components of the address like state and city and then visitors would be able to use the URL like www.yoursite.com/yourview/state/city for the page containing that View. Make sure that the order of the Contextual Filters in the Views UI is the order you want in the URL (state first, then city).

You won't need Views Global Filter if you don't need a UI for the user to set state and city and are happy to always have them use the URL+arguments to set state and city.

Note however that strictly speaking this approach is not identical to "contextual filter for proximity" in the sense that it is not constrained by a specified distance (i.e. a circular or perhaps square area). Instead it's constrained by the perimeter of city. But for your application the difference between the two may be of little importance.

Rik

johnhorning’s picture

Thanks for the tip, but I need to be able to easily go from the "city" view to a broader view that would include surrounding areas. I may want to hire you to help me come up with the exact solution.
John

rdeboer’s picture

Status: Active » Fixed

@johnhrning, #5
Sure, I'm available at the moment. Contact me via my contact form if you need help.
Rik

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.