2013-04-20 146 views
1

下面的方法一直返回0,我找不到原因!請幫忙!當它不應該返回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

發佈您的logcat的詳細信息。 – 2013-04-20 03:36:47

+0

你在設備上測試它嗎? – 2013-04-20 03:37:39

+0

'loc'的值是什麼?你只顯示'currentLocation'的值。 – FoamyGuy 2013-04-20 03:37:44

回答

1

取絕對值的平方根,而不是周圍的其他方式。它可能是NaN,它將它設置爲零或類似的東西。

(固定它)

+1

很高興在修復問題後看到有人共享+1 – stinepike 2013-04-20 03:52:47

相關問題