计算纬度/长度列表之间的距离
我有(示例列表)[[1,2], [3,4], [5,6], [7,8], ...]
的形式List<List<Double>>
。这些基本上是纬度和经度的列表,我想计算它们之间的距离。我有(Lat1, Lon1, Lat2, Lon2)
的距离计算方法。计算纬度/长度列表之间的距离
即在第一次迭代中从上述列表中取出(1,2,3,4)并计算距离。在下一次迭代中,我需要通过(3,4,5,6)等等。然后我可以添加所有迭代的距离来计算总距离。
所以我写了这个方法写入了4个值。我在开发for
循环时遇到问题,它会将正确的值传递给计算距离的方法。
你可以试试:
List<List<Double>> locations = ...
double totalDistance = 0;
for (int i = 0; i + 1 < locations.size(); i++) {
List<Double> a = locations.get(i);
List<Double> b = locations.get(i + 1);
totalDistance += calcDistance(a, b);
}
calcDistance()
可以计算出你所提到的两个位置之间的距离的方法。
在我的情况下,CalcDistance需要4点(1,2)和(3,4)来计算前2个点之间的距离(说x)。那么它将需要(3,4)和(5,6)并计算距离(比如y)。在此之后,我可以将x + y加起来找出总距离。 – Intern 2013-03-13 00:56:05
@Intern我只是想告诉你一些提示。例如,你可以调用'calcDistance(a.get(0),a.get(1),b.get(0),b.get(1))'... – 2013-03-13 01:15:46
请发表您写下的代码 – 2013-03-13 00:43:07
@MarcinS。我在编写for循环时遇到了困难,这就是在这里发布它的原因。 – Intern 2013-03-13 00:48:29
[如何使用经度和纬度值计算两个位置之间的距离]的可能重复(http://stackoverflow.com/questions/6981916/how-to-calculate-distance-between-two-locations-using-their-经度和纬度) – 2013-03-13 11:22:41