It seems that the Distance/Proximity Filter, when a distance is too great, will return no results.

I have a tested and working view with Location/Proximity Filter with a location that is 400 miles from the inputted zip code. When I put in 2000 miles, it returns the same results. But when I request locations 4000 miles away, the view returns no results. These are both from fresh searches, that is, I've reloaded the view in between attempting the search

I've attached the exported view, and screenshots follow:

2000 miles

4000 miles

#23 location-fix-471040-23-earth_longitude_range-not-correct-D6.patch924 byteshutch
PASSED: [[SimpleTest]]: [MySQL] 329 pass(es). View
#17 0001-fix-471040-earth_longitude_range-not-correct-for-lar.patch1.24 KBaxel.rutz
PASSED: [[SimpleTest]]: [MySQL] 329 pass(es). View
Zip_code_filter_view.txt13.18 KBglass.dimly
4000-miles.png15.12 KBglass.dimly
2000-miles.png31.82 KBglass.dimly
Members fund testing for the Drupal project. Drupal Association Learn more


mrtoner’s picture

The cut-off appears to be 3285 -- anything above that and the view is empty.

That's for miles, though; it's 5288 in kilometers, the same distance.

YesCT’s picture

glass.dimly’s picture

I have a theme-based workaround for this issue, though it in no way addresses the bug itself, which is rather serious, if I do say so myself.

This code is to be embedded in a the themed location view, and simply checks the value that was passed to the view by the Distance/Proximity Filter and rewrites that value if it surpasses 3280 miles.

1) Create a template file that overrides the view's theme. For instance, the name of my view is zip-code-proximity-test-2 and so I make a template file called views-view--zip-code-proximity-test-2.tpl.php.

2) Then I figure out what views wants me to put there using the handy views "Theme: Information" and clicking the link that corresponds to the view I wish to create. I cut and paste it into the tpl.php file.

3) Next, I add this code:

<?php if ($GLOBALS['HTTP_GET_VARS']['distance']['search_distance'] > 3280 ) {
    $GLOBALS['HTTP_GET_VARS']['distance']['search_distance'] = 3280;

4) Make sure to empty your cache, and it should work.

Ofer Morag’s picture


Thanks for the code.

In which file may I insert this code to achieve the sought after results?



glass.dimly’s picture


Please re-read what I wrote above. What I am speaking of is the a tpl.php file created to theme a view. If you are unsure what I'm talking about, you may refer to the documentation on theming views.


osopolar’s picture

Workaround by the use of a custom helper module with the following code:

function custom_helper_form_views_exposed_form_alter(&$form, &$form_state) {
  // workaround to limit distance in the proximity filter
  if (isset($form_state['input']['distance']['search_distance']) && 3280 < $form_state['input']['distance']['search_distance']) {
    $form_state['input']['distance']['search_distance'] = 3280;
    drupal_set_message(t('Notice: A distance value of more than 3280 miles/km is currently not supported.'));
gooddesignusa’s picture

Thanks for the custom module code. Took me awhile to find this issue since it was posted a while back.

YesCT’s picture

Issue tags: +location useful code

thanks for the fix!
Still needs a proper fix/patch... :)

hutch’s picture

Can anyone confirm where the cutoff point is? Or why? This might lie in the maths in, over my head I'm afraid.

mrtoner in #1 suggests 3285 miles, 5288 kilometers or 5288000 meters (or a bit less to be safe)

These limits should be in the form validation functions in the argument and filter handlers, not in theme hook_form_alter.

A new function in might be the way, eg location_distance_check($dist, $unit). This could be called by validators.

Alternately they could be imposed in _location_convert_distance_to_meters() but this might lead to confounding results.

YesCT’s picture

Issue tags: +location bdragon check

Brandon is super busy, so if anyone can figure this out, please post. But I'll add the tag "location bdragon check" which I use for architecture type questions... or questions someone who know most of the code might be needed to answer, but that person could be anyone, I just picked a kind of bad name for the tag way back when. :)

hutch’s picture

OK, I'm happy to do the coding but these are policy decisions, once these are made ping me ;-)

Cliff’s picture

I have no idea why the values are what they are, but find it interesting that they are within 1% of 48 degrees, or two-fifteenths of Earth's circumference at the Equator. (They're right at 47.5 degrees.)

Earth rotates through that distance in 3 hours and 12 minutes (3:10, if we're using 47.5 degrees).

What's significant about any of that? I have no idea. Perhaps nothing at all. But if there is any significance to it, perhaps expressing the distance in these terms will jog the connection in someone else's mind.

rooby’s picture

Title: When distance inputted into Location/Proximity Filter > 4000 miles, view returns no results » Range functions in are not accurate for large distances (affects proximity views etc.)
Version: 6.x-3.1-rc1 » 6.x-3.1
Component: Location_views » Code

I created an issue (#844756: Range functions in are not accurate for large distances)about this before as I didn't see this one so that one is marked as a duplicate of this.
This is not a views specific issue, it goes deeper than that.

Here is my post from the above mentioned issue:

For original discussion of this issue see #821628: earth_longitude_range() in uses invalid values with asin()

Basically, the range functions use simplified logic that is inaccurate for large distances.
More complex functions are required that work properly for all distance values.

For reference, these are the around about the maximum values of distance that can be used with this function before you start getting inaccurate results, the max value changes relative to the latitude of the point you are measuring from (if my calculations are correct):

Latitude (degrees) Max distance value (metres)
1/-1 9907423
15/-15 8347076
30/-30 6673549
45/-45 5000957
60/-60 3331176
75/-75 1664567
89/-89 110946

I have seen better formulae for calculating this stuff that shouldn't suffer from this, they are just more complex.
I'll just have to get into math mode sometime and work it all out.

rooby’s picture

And to answer other conversation from this thread, we can't add help text to say that certain distances are not supported because the distance is not constant but varies depending on the latitude.
We just have to fix the math that does the range calculations.

rooby’s picture

Also, from memory the views should not return no results after that distance but any results outside of that distance will not be displayed.

I think that was how it was happening.

axel.rutz’s picture

Version: 6.x-3.1 » 7.x-3.x-dev
Status: Active » Needs review

cool, some math to chew on ;-) !

here is the patch (against 7.x-3.x) that fixes this.

and here some manual tests:

// these should all result in about +/-90 degrees
    [0] => -89.831528412
    [1] => 89.831528412
    [0] => -90.350932022
    [1] => 90.350932022
    [0] => -90.0582744791
    [1] => 90.0582744791
axel.rutz’s picture

1.24 KB
PASSED: [[SimpleTest]]: [MySQL] 329 pass(es). View
podarok’s picture

Status: Needs review » Active

#1931088: [META] Fixing tests tests were broken, so triggering to active

podarok’s picture

Status: Active » Needs review


podarok’s picture

Status: Needs review » Fixed

#17 commited pushed to 7.x-3.x

rooby’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Assigned: Unassigned » rooby
Status: Fixed » Patch (to be ported)

That's great thanks.

I'm thinking I will backport this to drupal 6 as it is a pretty major issue.

Someone else is also welcome to do it if they want.

podarok’s picture

Status: Patch (to be ported) » Needs review
hutch’s picture

924 bytes
PASSED: [[SimpleTest]]: [MySQL] 329 pass(es). View

Patch on fresh pull of location-6.x-3.x-dev attached, not tested.

podarok’s picture

podarok’s picture

Status: Needs review » Fixed

#23 commited pushed to 6.x-3.x-dev

Status: Fixed » Closed (fixed)
Issue tags: -Needs tests, -Needs manual testing

Automatically closed -- issue fixed for 2 weeks with no activity.