Implement click_sort in distance field handler
webnotwar - October 27, 2008 - 09:56
| Project: | Location |
| Version: | 6.x-3.x-dev |
| Component: | Location_views |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Description
I use drupal6 with wounderfull views2 and location. I created a view which displays a location and the distance to a specific point. When i enable the table-display and set the sorting to "Distance" the sorting will nor work correctly.
Sql-Query goes like this:
SELECT ... ORDER BY location_latitude ASC
but "location_latitude" is not the right way to sort by distance. MySql-Qeury must be:
$lat = latitude;
$lon = longitude;
SELECT SQRT( POW( 69.1 * ( l.latitude - ".$lat.") , 2 ) + POW( 69.1 * ( ".$lon." - l.longitude ) * COS( l.latitude / 57.3 ) , 2 ) ) AS distance .... ODER BY distance ASC
is this a known problem? How to fix that?
Thank you for your help!

#1
I implemented
location_handler_field_location_distance::click_sort(). For that I moved the code that retrieves the reference location to a designated functionlocation_handler_field_location_distance::_get_reference_location()so that it can be used bylocation_handler_field_location_distance::query()as well aslocation_handler_field_location_distance::click_sort().#2
The patch also fixes #356488: Distance Field Handler does not accept all valid longitudes and latitudes.
#3
Patch did not apply and had to be re-rolled.
Works as advertised.