/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 737 by torben, Wed May 19 07:40:00 2010 UTC revision 741 by torben, Wed May 19 12:56:10 2010 UTC
# Line 101  public class StationDAO { Line 101  public class StationDAO {
101                  return result;                  return result;
102          }          }
103                    
104          //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
105            // in denmark 1.5dg latitude ~ 165km, 2.5dg longitude ~ 155km
106            
107            // the ultra fast method  (and only slightly inaccurate as long as we only cover a limited geographically area)
108            // is using an aproximation of the length of 1 latitude degree and 1 longitude degree and just use pythagoras to
109            // calculate the distance:
110        //     sqrt( power(abs(latitude-?)*111320, 2) + power(abs(longitude-?)*63000,2) )::int as calcdist
111            
112          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {
113                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +
114                                           "       earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " +                                           "       earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " +
115                                           "FROM trainstations " +                                           "FROM trainstations " +
116                                           "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 " +
117                                           "ORDER BY calcdist ASC " +                                           "ORDER BY calcdist ASC " +
118                                           "LIMIT 4 ";                                           "LIMIT 4 ";
119                  List<StationBean> result;                  List<StationBean> result;

Legend:
Removed from v.737  
changed lines
  Added in v.741

  ViewVC Help
Powered by ViewVC 1.1.20