--- android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java 2010/05/19 07:40:00 737 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/StationDAO.java 2010/05/19 12:56:10 741 @@ -101,12 +101,19 @@ return result; } - //the "hack" with max 2.5 degrees latitude and longitude is only valid since we only service danish trains + //the "hack" with max 1.5 degrees latitude and 2.5 degrees longitude is only valid since we only service danish trains + // in denmark 1.5dg latitude ~ 165km, 2.5dg longitude ~ 155km + + // the ultra fast method (and only slightly inaccurate as long as we only cover a limited geographically area) + // is using an aproximation of the length of 1 latitude degree and 1 longitude degree and just use pythagoras to + // calculate the distance: + // sqrt( power(abs(latitude-?)*111320, 2) + power(abs(longitude-?)*63000,2) )::int as calcdist + public List getByLocation(double latitude, double longitude) throws SQLException { String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," + " earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " + "FROM trainstations " + - "WHERE enabled = true AND abs(latitude-?)<2.5 AND abs (longitude-?)<2.5 " + + "WHERE enabled = true AND abs(latitude-?)<1.5 AND abs(longitude-?)<2.5 " + "ORDER BY calcdist ASC " + "LIMIT 4 "; List result;