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!

CommentFileSizeAuthor
#3 click_sort2.patch2.5 KBnickl
#1 click_sort.patch2.6 KBtraxer

Comments

traxer’s picture

Title: sort by distance » Implement click_sort in distance field handler
Version: 6.x-3.0-rc2 » 6.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new2.6 KB

I implemented location_handler_field_location_distance::click_sort(). For that I moved the code that retrieves the reference location to a designated function location_handler_field_location_distance::_get_reference_location() so that it can be used by location_handler_field_location_distance::query() as well as location_handler_field_location_distance::click_sort().

traxer’s picture

nickl’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.5 KB

Patch did not apply and had to be re-rolled.
Works as advertised.

ankur’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD and DRUPAL-6--3

Status: Fixed » Closed (fixed)

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