/[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 714 by torben, Fri May 7 17:08:11 2010 UTC revision 739 by torben, Wed May 19 09:53:25 2010 UTC
# Line 101  public class StationDAO { Line 101  public class StationDAO {
101                  return result;                  return result;
102          }          }
103                    
104            //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          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {          public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException {
107                  String SQL = "SELECT * FROM ( "+                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +
108                  "               SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," +                                           "       earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " +
109                  "                     earth_distance( ll_to_earth(latitude,longitude), ll_to_earth(?,?))::int AS calcdist " +                                           "FROM trainstations " +
110                  "               FROM trainstations " +                                           "WHERE enabled = true AND abs(latitude-?)<1.5 AND abs(longitude-?)<2.5 " +
111                  "               WHERE enabled = true " +                                           "ORDER BY calcdist ASC " +
112                  "       ) AS trainstations2 " +                                           "LIMIT 4 ";
                 "ORDER BY calcdist ASC " +  
                 "LIMIT 4 ";  
113                  List<StationBean> result;                  List<StationBean> result;
114                  Connection conn = null;                  Connection conn = null;
115                  PreparedStatement stmt = null;                  PreparedStatement stmt = null;
# Line 119  public class StationDAO { Line 119  public class StationDAO {
119                          stmt = conn.prepareStatement(SQL);                          stmt = conn.prepareStatement(SQL);
120                          stmt.setDouble(1, latitude);                          stmt.setDouble(1, latitude);
121                          stmt.setDouble(2, longitude);                          stmt.setDouble(2, longitude);
122                            stmt.setDouble(3, latitude);
123                            stmt.setDouble(4, longitude);                  
124                          res = stmt.executeQuery();                          res = stmt.executeQuery();
125                          result = convertResultset(res);                          result = convertResultset(res);
126                                                    

Legend:
Removed from v.714  
changed lines
  Added in v.739

  ViewVC Help
Powered by ViewVC 1.1.20