我有一个问题,因为我不知道如何传递得到的值从我的经纬度到我的查询到计算两点之间距离的方法?我有一个查询,它按id下载一个值user,并按id返回纬度和经度user
@Override
public UserApp getUserByIdLocation(int idUser) {
Session session = this.sessionFactory.openSession();
UserApp userApp =
(UserApp) session.createQuery("SELECT latitude, longitude FROM pl.edu.wszib.model.UserApp WHERE idUser = " + idUser ).uniqueResult();
session.close();
System.out.println(userApp);
return userApp;
}
我有查询哪个下载经纬度车辆的id
@Override
public Vehicle getVehicleLocation(int idVehicle){
Session session = this.sessionFactory.openSession();
Vehicle vehicle =
(Vehicle) session.createQuery("SELECT latitude, longitude FROM pl.edu.wszib.model.Vehicle WHERE idVehicle = " + idVehicle).uniqueResult();
session.close();
System.out.println(vehicle);
return vehicle;
}
我有计算两点之间距离的方法
@Override
public double distance(double lat1, double lon1, double lat2, double lon2){
double R = 6371e3; // metry
double φ1 = lat1 * Math.PI / 180; // φ, λ w radianach
double φ2 = lat2 * Math.PI / 180;
double Δφ = (lat2-lat1) * Math.PI / 180;
double Δλ = (lon2-lon1) * Math.PI / 180;
double a = Math.sin (Δφ / 2) * Math.sin (Δφ / 2) +
Math.cos (φ1) * Math.cos (φ2) *
Math.sin (Δλ / 2) * Math.sin (Δλ / 2);
double c = 2 * Math.atan2 (Math.sqrt (a), Math.sqrt (1-a));
double d = R * c; // w metrach
d = Math.round(d);
return d/1000;
}
我的userapp类
@Entity
@Table(schema="dbo",name = "UserApp")
public class UserApp implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idUser;
private String username;
private String password;
private String name;
private String surname;
private String email;
private double latitude;
private double longitude;
private String role;
private String locationName;
我的车辆等级
@Entity
@Table(schema="dbo",name = "Vehicle")
public class Vehicle {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idVehicle;
private int idGroupVehicle;
private String brand;
private String model;
private int maxRange;
private int weight;
private double pricePerSale;
private int maxSpeed;
private double latitude;
private double longitude;
private String locationName;
还有我的远程课程
public class Distance {
private double lat1;
private double lon1;
private double lat2;
private double lon2;
我现在如何从这个查询中输入下载值并根据这些值计算距离有人能解释一下吗?
暂无答案!
目前还没有任何答案,快来回答吧!