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 |
105 |
public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException { |
public List<StationBean> getByLocation(double latitude, double longitude) throws SQLException { |
106 |
String SQL = "SELECT * FROM ( "+ |
String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," + |
107 |
" SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address," + |
" earth_distance( earth_coord, ll_to_earth(?,?))::int AS calcdist " + |
108 |
" earth_distance( ll_to_earth(latitude,longitude), ll_to_earth(?,?))::int AS calcdist " + |
"FROM trainstations " + |
109 |
" FROM trainstations " + |
"WHERE enabled = true AND abs(latitude-?)<2.5 AND abs (longitude-?)<2.5 " + |
110 |
" WHERE enabled = true " + |
"ORDER BY calcdist ASC " + |
111 |
" ) AS trainstations2 " + |
"LIMIT 4 "; |
|
"ORDER BY calcdist ASC " + |
|
|
"LIMIT 4 "; |
|
112 |
List<StationBean> result; |
List<StationBean> result; |
113 |
Connection conn = null; |
Connection conn = null; |
114 |
PreparedStatement stmt = null; |
PreparedStatement stmt = null; |
118 |
stmt = conn.prepareStatement(SQL); |
stmt = conn.prepareStatement(SQL); |
119 |
stmt.setDouble(1, latitude); |
stmt.setDouble(1, latitude); |
120 |
stmt.setDouble(2, longitude); |
stmt.setDouble(2, longitude); |
121 |
|
stmt.setDouble(3, latitude); |
122 |
|
stmt.setDouble(4, longitude); |
123 |
res = stmt.executeQuery(); |
res = stmt.executeQuery(); |
124 |
result = convertResultset(res); |
result = convertResultset(res); |
125 |
|
|