Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 计算与阵列中点的距离_Android_Api_Google Maps - Fatal编程技术网

Android 计算与阵列中点的距离

Android 计算与阵列中点的距离,android,api,google-maps,Android,Api,Google Maps,我正在开发一个Android应用程序来跟踪用户的位置。我让它在本地运行,因此我的LatLng存储在一个数组中: ArrayList<LatLng> points = new ArrayList<>(); ArrayList points=new ArrayList(); 在onLocationChanged中,它然后用它画一条多段线,这一切都非常适合我。我想计算一下整个旅程的距离。有没有一种方法可以使用我的数组执行此操作 你可以做一个循环,穿过你的阵列,计算两个连续点

我正在开发一个Android应用程序来跟踪用户的位置。我让它在本地运行,因此我的
LatLng
存储在一个数组中:

ArrayList<LatLng> points = new ArrayList<>();
ArrayList points=new ArrayList();

onLocationChanged
中,它然后用它画一条多段线,这一切都非常适合我。我想计算一下整个旅程的距离。有没有一种方法可以使用我的数组执行此操作

你可以做一个循环,穿过你的阵列,计算两个连续点之间的距离。然后将计算出的每段距离相加,得到整个行程距离。这应该如下所示(在伪代码中):


要计算位置点之间的距离,至少需要两个点

计算可在此处找到:

尝试在中使用


您只需对列表中两个连续点之间的所有距离求和?但闻起来像是作业:)
totalDistance;
for(points in listOfPoints){
    nextPoint = listOfPoints.indexof(point + 1);
    distance = computeDistance(point, nextPoint);
    totalDistance.add(distance);
}
double totalDistanceInMeters = SphericalUtil.computeLength(points);