Reputation: 7568
The method below keeps returning 0, and I cannot figure out why! Please help!
currentLocation.setLatitude(38.03211);
currentLocation.setLongitude(-78.51002);
and longitude/latitude of if loc is 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())));
}
Upvotes: 1
Views: 78
Reputation: 7568
Take the squareroot of the absolute value, not the other way around. It is probably coming up NaN which is just setting it to zero or something like that.
(this fixed it)
Upvotes: 1