Here are the changes I made to allow proximity filter based on user location.
I have never submitted a drupal module change, so let me know if there is a better way to do this.
Depends on views, location, and user location.
Thanks,
Ben
PS. I use this to restrict display of events(nodes) to those close to the user.
Index: modules/location/handlers/location_views_handler_filter_proximity.inc
===================================================================
--- modules/location/handlers/location_views_handler_filter_proximity.inc (revision 8)
+++ modules/location/handlers/location_views_handler_filter_proximity.inc (working copy)
@@ -161,6 +161,7 @@
// Used from the distance field.
function calculate_coords() {
+ global $user;
if (!empty($this->value['latitude']) && !empty($this->value['longitude'])) {
// If there are already coordinates, there's no work for us.
return TRUE;
@@ -189,16 +190,22 @@
return false;
}
}
+
if ($this->value['get_origin_from_url']) {
- if (arg(0) == 'node' && is_numeric(arg(1)) && $node = node_load(arg(1))) {
- $this->value['latitude'] = $node->location['latitude'];
- $this->value['longitude'] = $node->location['longitude'];
- }
- elseif (arg(0) == 'user' && is_numeric(arg(1)) && $user = user_load(arg(1))) {
+ #if (arg(0) == 'node' && is_numeric(arg(1)) && $node = node_load(arg(1))) {
+ # $this->value['latitude'] = $node->location['latitude'];
+ # $this->value['longitude'] = $node->location['longitude'];
+ #}
+ #elseif (arg(0) == 'user' && is_numeric(arg(1)) && $user = user_load(arg(1))) {
// @todo get user location
- echo "boo";
- }
+ //echo "boo";
+ $user_location = location_load_locations($user->uid, 'uid');
+ $user_location = $user_location[0];
+ $this->value['latitude'] = $user_location['latitude'];
+ $this->value['longitude'] = $user_location['longitude'];
+ return true;
+ #}
}
if (empty($this->value['latitude']) || empty($this->value['longitude'])) {
@@ -211,7 +218,6 @@
if (empty($this->value)) {
return;
}
-
// Coordinates available?
if (!$this->calculate_coords()) {
// Distance set?
@@ -227,10 +233,9 @@
$lat = $this->value['latitude'];
$lon = $this->value['longitude'];
-
$distance_meters = _location_convert_distance_to_meters($this->value['search_distance'], $this->value['search_units']);
-
- $latrange = earth_latitude_range($lon, $lat, $distance_meters);
+
+ $latrange = earth_latitude_range($lon, $lat, $distance_meters);
$lonrange = earth_longitude_range($lon, $lat, $distance_meters);
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | location_views_handler_filter_proximity.inc_.patch | 2.3 KB | benjah |
Comments
Comment #1
jorge commentedWow. Thank you for fixing this..if it works. This is just what I need, but the formatting is all funky. Can you upload as patch, or paste in as code?
Comment #2
benjah commentedOK. This is my first attempt at creating a patch file. Please let me know if it works.
If you have any problem, here is the important part.
Directly inside the calculate_coords function, Add the following.
global $user;
Then under "// @todo get user location", add the following.
$user_location = location_load_locations($user->uid, 'uid');
$user_location = $user_location[0];
$this->value['latitude'] = $user_location['latitude'];
$this->value['longitude'] = $user_location['longitude'];
This is not the correct way of using the "get_origin_from_url" checkbox.
In this case, I am getting the user location of the logged in user, instead of the url.
I am open to suggestions on how to better incorporate this.
Once again, the depends on views, location, and user location modules.
You must have get_origin_from_url checked. It also only supports one location per user.
(Here is the commands I used.)
svn diff -r8 --diff-cmd diff -x -wup modules/location/handlers/location_views_handler_filter_proximity.inc > /Users/ben/location_views_handler_filter_proximity.inc.patch
Comment #3
socialnicheguru commentedsubscribing
Comment #4
drumnjo commentedsubscribe
Comment #5
tonyhrx commentedHmm. The patch does not install properly when running Patch on the latest version of the Location module.
The inc file also has comments deleted out and some code so its not easy to see how to patch it manually from the patch file.
Any help anyone?
Ta
Comment #6
yesct commentedPlease check to see if this is still a problem in the new release. If it is, reply with a new summary and set the status back to active. (there was a lot of work done on proximity in the new release)
Comment #7
ankur commentedI believe this feature has been obsoleted by some views integration features that have been added since this original bug report.