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; |
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 |
|
|