We’re just about to add location-based services to the BeGrand.net website and will be offering a way to search for events close to your post code.
As part of the build we’re using the excellent Location module which provides a proximity search by default. The latest version at time of writing is 6.x-3.1.
We have an exposed block that provides the basic search form and this leads to a Google map displaying events nearby – so you can search for events within 10 miles of CB24 for example. The search works well, but I wanted a way of displaying the filter on the output page. I knew that I could specify PHP code in the header for the view on the page in Views, but struggled to find the code I needed to return the post code, distance and units to show. Finally, I found the answer. Here it is:
"; ";$view = views_get_current_view();
if (isset( $view->exposed_input['distance'])) {
echo "
Upcoming events within ";
echo $view->exposed_input['distance']['search_distance']." ";
echo $view->exposed_input['distance']['search_units']."s of ";
echo $view->exposed_input['distance']['postal_code']."
} else {
echo "
All upcoming events
}
So now, when you search within 10 miles of CB24 the header is displayed as:
Upcoming events within 10 miles of CB24
I’ve added a conditional statement so that an alternative header is displayed if the filter hasn’t been set.
Job done, which is nice.
{ 1 comment }
It’s official. My search for the perfect to-do solution is over. I recently got a MacBook Pro as my primary weapon of choice from my employers and that has allowed me to do what I know is right and use the amazingly simple, but incredibly effective, Things from