Can the distance filter in location views be based on the user locations rather than just long/lat and postcode?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sziggle’s picture

Title: distance filter by user location » views distance filter by user location

+1 for this request. the views Distance / Proximity display field can default to the user's location, and the views Distance / Proximity sort criteria can default to the user's location. if the filter could do it as well, this views implementation would do exactly what i need; allow me to create a view / page / block that shows a list of nodes with locations that are within some fixed distance of the user's location (without making the user input their zip code).

[if anyone knows a way to mangle views into constructing the right query for this use case prior to this module supporting it, please let me know cuz i am on a deadline... of course]

-thanks!

YesCT’s picture

tagging to help find if this is a duplicate request, this might also be related to views arguments.

might be a duplicate of #357295: Proximity Search based on lat/lon, using views arguments

mkinnan’s picture

I am also trying to do this. I want to create a Map or a Table of nodes relative to a user's location. I thought this might be done with views relationships, but there are not any for a user's location ... at least from what I have seen.

chaosprinz’s picture

Subscribing.
I tried to give a relationship to the exposed-proximity-filter, but it doesent work. When i use the relationship on other exposed location-filter it works.
Btw. its a relationship to node-relativity: parent-node-id
But had the same issue, when trying other relationships. This would be a real great feature.

sagannotcarl’s picture

For my needs this does seem like a dupe of #357295: Proximity Search based on lat/lon, using views arguments (for vice versa), but on that thread there is some talk of a more programmatic way to do it and I'm more interested in having this functionality in the views interface.

There is a description here #334846: Center Gmap on Node passed as argument in view (#2) that seems like what I want but there is one step that I don't understand.

creativegenius’s picture

subscribe

evanbarter’s picture

Status: Active » Needs review
FileSize
2.7 KB

This is some functionality I'd love for a site I am building, so I thought I'd get my hands dirty. I'll throw some more hours at this tomorrow if no one picks it up in the next 24 hours.

Couple of things: (1) I've done little to no testing of this other than checking it doesn't completely bomb with errors, because (2) It's well after midnight, and (3) This is the first patch I've ever done for Drupal or a Drupal module!

Patch provides a new "Form mode" (I don't like that name either) which allows user to select one of the locations attached to the user itself. At the moment it only checks to see if the location has a name and then runs with that. This is a bad bad bad idea since this field can be disabled, so this is the first thing that needs to be worked on. I was thinking of doing it based on the lat/lon of the location and inferring a name for it based on what data is available. Not sure how this will work with JIT geocoding, something for me to look in to I guess. Please review and comment!

Cheers,
Evan

evanbarter’s picture

FileSize
2.87 KB

Fixed a blocker, locations will also fall back to title "Location #x" now when there's no name.

jdln’s picture

Has any progress been made on this?
Thanks

Todd Young’s picture

anything yet?

YesCT’s picture

jdin and yountod (and others) thanks for your interest; sometimes we need reminders to look at these issues.

Forgive me if you already know this, but sometimes people dont...
Drupal and Drupal modules in general and specifically location do not have any people paid to code or maintain them. The people who work on it do it without getting paid (well, some people might get paid if their company is using location module, but I dont know of anyone in that situation ... anyway).

So, to get progress on this issue we need your help. Yes, YOU. :)
But I (and others) can help you do that.

Check out how to apply patches:
http://drupal.org/patch/apply

And how to review patches:
http://drupal.org/patch/review is some official words on how to do a
review. But in general you try out the patch and then you say if the patch patches, if
it didn't: copy and paste the error. Say how the site functioned
before (what was wrong), say how the patch changed the behavior (did
it fix something? did it break anything else?), also, a code review of
code style http://drupal.org/coding-standards and security
http://drupal.org/writing-secure-code and if it is good for themers (I
dont know of a link for this... ) BUT you do NOT have to do all of the
review, or all of it at once. Do what small parts of the review you can, and post those results.
Someone else can then review the other parts (say theme or security or
whatever), or you can come back later add add to the review.

here is an example of a good review: http://drupal.org/node/182786

Dont be afraid to change things with the issue, add better words to
the title, mark things as duplicates, say it needs work, or needs
review... If someone doesn't agree, someone will change details back
or to something else. :)

I dont have any special position in location... I'm "just a user" :)
... just a user that want to use location and wants to make it easier
for the maintainer to maintain so it is maintained. :)

Together we can get location in a good place!

Also, note you will want to set up a test site so you dont mess up your live site.

You can get live help from me (YesCT) or anyone in IRC:
http://drupal.org/irc
People in IRC especially like to help people who go there and say "I never reviewed a patch before. I want to contribute. What do I do?" ... or something like that.

Todd Young’s picture

I rolled up my sleeves and gave it a shot - it seems to be working with one substantial glitch yet to be knocked out.

I'm hope I'm talking apples-and-apples here? You can check out the thread (and the code) at #767946: Allow the proximity filter to use a node argument's location as a center

Scroll down to #5 to see where I modified nicholasThompson's code to consider users instead of nodes.

dawehner’s picture

Status: Needs review » Needs work
+++ location_views_handler_filter_proximity.inc	2010-02-09 21:08:18.000000000 +0800
@@ -209,7 +235,22 @@ class location_views_handler_filter_prox
+    if ($this->options['type'] == 'user') {
+			if (!empty($this->value['location'])) {
+				$location = location_load_location($this->value['location']);
+				if (empty($location['latitude']) || empty($location['longitude'])) {
+					return false;
+				} else {
+					$this->value['latitude'] = $location['latitude'];
+					$this->value['longitude'] = $location['longitude'];
+				}
+			} else {
+				return false;
+			}
+		}
+		

tabs. Please use spaces instead

Powered by Dreditor.

artscoop’s picture

Hi,
There may be something very simple for this.

For example, you can make the distance filter work with the current user location by letting the Lat, Lon an Postalcode fields empty.
That would use the user location by default, since there is no point in using a (0,0) point for reference.

Hmh oh well, it has already been done just above :D
I think this patch is the way to go.

artscoop’s picture

Well no, this code was not meant for non exposed filters,
this code should be useful.

    if (empty($location['latitude']) || empty($location['longitude'])) {
      global $user;
      $locations = location_load_locations ($user->uid, 'uid');
      foreach ($locations as $location) {
					$this->value['latitude'] = $location['latitude'];
					$this->value['longitude'] = $location['longitude'];
      }
    }    

just after

        // @@@ Implement full address lookup?
        return false;
      }
    }

I may provide a patch later.

rooby’s picture

Status: Needs work » Closed (duplicate)

Thanks for the work on this patch.

I know this issue has been around longer but I am marking it as a duplicate of #718928: add options to set coordinates w/ user location, PHP code for field, filter because that patch has more functionality.

Previously it did not have your option to select which of the users locations to use in the exposed filter so I added that to the newest version of the patch.

If there is anything else that the patch here was going to provide that the other issue doesn't cover just bring it up in the other issue and it can be added.