The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.
public void proximityToEndPoint(String username, String password,
double latitude, double longitude) {
double radius = 6371;
connect2DB();
if (this.conn != null) {
try {
String query = "";
PreparedStatement statement;
@SuppressWarnings("unused")
ResultSet resultSet;
double lat1 = 33.420243;
double long1 = -111.936125;
double lat2 = 33.3070;
double long2 = 111.6783;
query = "SELECT username, password"
+ "FROM endpoint, rs_user\n" + "WHERE lat AND long IN "
+ calculateDistance(lat1, long1, lat2, long2);
statement = this.conn.prepareStatement(query);
statement.setString(1, username);
statement.setString(2, password);
resultSet = statement.executeQuery();
this.conn.commit();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
closeDBConnection();
}
public static double calculateDistance(double lat1, double lng1,
double lat2, double lng2) {
int r = 6371; // average radius of the earth in km
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lng2 - lng1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = r * c;
double e = 0.621371 * d;
return e;
}
How do you determine whether a user in a certain radius of a location (represented by a set of coordinates in latitude and longitude)?
SELECT the_geom
FROM geom_table
WHERE the_geom && 'BOX3D(90900 190900, 100100 200100)'::box3d
AND
ST_Distance(the_geom, ST_GeomFromText('POINT(100
I don't understand your schema very well the only table that has latitude is table location but no other table references it.
select * from location as loc where loc.lat between 15.0 and 20.0 and
loc."long" between 5.0 and 20.0;
select calculateDistance( loc.lat, loc."long", 18.4,7.6 ) as distance, loc.* from location as loc where calculateDistance( loc.lat, loc."long", 18.4,7.6 )
< 5.0;