下面的方法一直返回0,我无法弄清楚原因!请帮忙!
currentLocation.setLatitude(38.03211);
currentLocation.setLongitude(-78.51002);
和loc的经度/纬度是 38.03161, -78.51075,
public double getDistance(HistoricalLocation loc) {
return (double) Math.abs(Math.sqrt((currentLocation.getLatitude() - loc
.getLatitude())
* (currentLocation.getLatitude() - loc.getLatitude())
+ (currentLocation.getLongitude() - loc.getLongitude())
* (currentLocation.getLongitude() - loc.getLongitude())));
}
答案 0 :(得分:1)
取绝对值的平方根,而不是相反。它可能会出现NaN,只是将它设置为零或类似的东西。
(这修好了)