【发布时间】:2016-04-21 18:51:27
【问题描述】:
欢迎提供任何良好且准确的行驶距离示例。我尝试通过计算纬度和经度。存储先前和当前点数据并获取距离并在车速 = 0 时每 5 秒添加一次我检查了多轮移动车辆,每次我得到不同的 KM 距离。不准确。移动车辆路径距离计算的任何精度解决方案。
private double journeyPathDistance(double currentLat, double currentLng) {
if (isFirstTime && vehicleSpeedValue != 0) {
Location loc1 = new Location("");
loc1.setLatitude(currentLat);
loc1.setLongitude(currentLng);
Location loc2 = new Location("");
loc2.setLatitude(currentLat);
loc2.setLongitude(currentLng);
isFirstTime = false;
prevLat = currentLat;
prevLng = currentLng;
distanceKms = loc1.distanceTo(loc2) / 1000;
} else {
if (vehicleSpeedValue != 0) {
Location loc1 = new Location("");
loc1.setLatitude(prevLat);
loc1.setLongitude(prevLng);
Location loc2 = new Location("");
loc2.setLatitude(currentLat);
loc2.setLongitude(currentLng);
prevLat = currentLat;
prevLng = currentLng;
distanceKms += (loc1.distanceTo(loc2) / 1000);
}
}
return distanceKms;
}
【问题讨论】: