Views Argument Handler for Proximity

Dustin Currie - October 16, 2009 - 12:26
Project:Location
Version:6.x-3.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I have created a views argument handler for proximity.

You can use the argument in two ways, by postal code and distance or by coordinate and distance.

Example: view path is content-listing

content-listing/[postal_code]+[distance]
content-listing/75214+10

The above argument will restrict content within 10 miles of zipcode 75214.

Coordinates can also be passed.

content-listing/[lattitude],[longitude]+[distance]
content-listing/32.783,-96.8+25

Options for the argument handler are:

* Coordinate Description
Radio for either postal code that gets translated to rough coordinates or exact coordinates
* Unit Type
Miles or Kilometers. Unit type is set as an option, not encoded in the argument.
* Method
The views query is modified similar to how the proximity filter already works. And you can choose between a radial or rectangular search.

location.views.inc was modified to register the new handler in

location_views_handlers() and location_views_data()

A new file handlers/location_handler_argument_location_distance.inc was created.

I need to do a little cleanup and will post the code later this weekend. Bdragon, can we schedule a time for me to run some questions by you on IRC or email?

AttachmentSize
proximity-argument.png56.19 KB

#1

DamienMcKenna - October 16, 2009 - 13:02

Does it support a default on the second argument, so that it would work as just "content-listing/75214"?

#2

Dustin Currie - October 16, 2009 - 13:12

Not currently. I didn't even think of that until I read your post. It's a good idea. I'll make that change before I post the code here.

#3

DamienMcKenna - October 16, 2009 - 14:41

Great, I look forward to testing it :-)

#4

Dustin Currie - October 16, 2009 - 20:22

I think that postal code only is not appropriate to use with a proximity argument handler. It should have its own argument handler.

Doesn't like me adding the new file as a .inc, so I just appended .patch. It's not really a patch file.

AttachmentSize
location.views_.inc_.patch 1.38 KB
location_handler_argument_location_distance.inc_.patch 5.37 KB

#5

bara.munchies - October 23, 2009 - 08:04

i can confirm that the patch and inc file works. very nice work, thanks you for your effort. karma+1

i noticed that the sorting by proximity/distance as well as the display of proximity do not work. the field is empty.

it's still very usable to show all marker inside a defined distance.

#6

corona ronin - October 25, 2009 - 17:36

Awesome. Excellent. Check out http://drupal.org/node/357295 which is the main queue for this problem....

What's the process on getting this committed? I'll install a fresh installation of drupal and load it on and write a little report on how it works/how it can be improved.

Thanks again for spending the time to do this!

#7

dchampine - October 26, 2009 - 01:06

Can't get postal code to set
I've patched the -dev version and added the handler which exposes the functionality just fine, but I can't get the argument to work properly. Neither of the radios are checked for type of center point and the query seems to indicate that lat/long is selected even when I specifically select postal code and save? AND (location.latitude > 0 AND location.latitude < 0 AND location.longitude > 0 AND location.longitude < 0)
(it may just be for validation and not affecting the query - not sure). I'm not a php coder, but I'm pretty handy with drupal/cck/views/panels and happy to help with testing/config as I really need to get zipcode arguments to work for my production site.
Drupal 6.14
MySQL 5.1.36
Views 6.x-2.6

#8

Dustin Currie - October 26, 2009 - 14:53

dchampine, email me dustinc@getlevelten.com so we can get together and resolve what you are seeing.

#9

held69 - November 1, 2009 - 21:03

Can someone confirm if the patches above can be used for use with cck location as well?

Thanks.

#10

fletch11 - November 2, 2009 - 14:27

subscribe

#11

jereoms - November 18, 2009 - 00:38

I am not sure I understand how to implement once you have applied the patch and added the new .inc file. I believe I have done those parts correctly and was expecting to see a change available in my views configuration area. Where should I go to implement this feature?

Thanks

#12

jereoms - November 24, 2009 - 02:35

Sorry for the mixup, I found my error and it is simply a matter of adding the Proximity/Location drop down to the arugments view area.

 
 

Drupal is a registered trademark of Dries Buytaert.