possible fix for proximity filter based on user location
| Project: | Location |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
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);

#1
Wow. 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?
#2
OK. 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
#3
subscribing
#4
subscribe