gpt4 book ai didi

android - 如何计算Android中两个lat long之间的距离和时间?

转载 作者:行者123 更新时间:2023-11-29 21:13:16 24 4
gpt4 key购买 nike

我在下面使用 for-loop。如果代码不在循环内,则代码计算正确,但我想创建一个没有的列表。距离和时间。

KIEL = new LatLng(lat, log);                    
for(i=0;i<jarray.length;i++){
KIEL = new LatLng(lat, log);
doc = md.getDocument(fromPosition, KIEL,
GMapV2Direction.MODE_DRIVING);
duration = "" + md.getDurationValue(doc);
distance = md.getDistanceText(doc);

HashMap<String, String> map = new HashMap<String, String>();
map.put("distance", distance);
map.put("time", duration );

// // adding HashList to ArrayList
locationlist.add(map);
}

docDocument 类的一个对象,它计算两个位置之间的距离和时间。但是当我在循环中使用这个方法时,它不会显示任何数据。如何解决?

最佳答案

使用 Location.distanceTo(Location) 它会给你两个不同位置之间的距离。

喜欢 distance = currentLocation.distanceTo(newLocation);

关于android - 如何计算Android中两个lat long之间的距离和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22141167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com