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

traxer - January 5, 2009 - 22:00
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

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().

AttachmentSize
click_sort.patch 2.6 KB

#2

traxer - January 9, 2009 - 12:24

#3

nickl - November 30, 2009 - 18:53
Status:needs review» reviewed & tested by the community

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

AttachmentSize
click_sort2.patch 2.5 KB
 
 

Drupal is a registered trademark of Dries Buytaert.