给定一个经纬度数组 [(x1,y1),(x2,y2),(x3,y3),(x4,y4),(x5,y5)...] 其中 x 是纬度,y 是经度 I想要返回一个数组,它们之间的距离小于 5KM。例如,返回的数组将是 (x2,y2),(x3,y3) 这意味着这些点之间的距离小于 5km。我正在使用 Haversine 算法来计算两点之间的距离。Haversine.distance(x1,y1,x2,y2).我如何在java中实现这个?
这是我试过的,
public static class Point{
private final double latitude;
private final double longitude;
}
Point p1 = new Point(53.594952,-1.291583);
Point p2 = new Point(53.383100,-1.179820);
Point p3 = new Point(53.594952,-1.179120);
Point p4 = new Point(53.594952,-1.279120);
Point p5 = new Point(53.594952,-1.479120);
Point p6 = new Point(53.594952,-1.339120);
Point[] points = {p1, p2, p3, p4, p5, p6};
Point[] nearPoints = new Point[points.length];
for (int i = 0; i <= points.length - 1; i++) {
if (Haversine.distance(points[i].latitude, points[i].longitude, points[i + 1].latitude, points[i + 1].longitude) < 5) {
nearPoints[i] = points[i];
}
}
噜噜哒
相关分类