当它不应该返回零

时间:2013-04-20 03:35:12

标签: java android eclipse return coordinates

下面的方法一直返回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())));

}

1 个答案:

答案 0 :(得分:1)

取绝对值的平方根,而不是相反。它可能会出现NaN,只是将它设置为零或类似的东西。

(这修好了)