Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.
Become a Premium Member and unlock a new, free course in leading technologies each month.
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)? Add your voice to the tech community where 5M+ people just like you are talking about what matters.
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.