I am in process to implement "Distance Calculator" - that we used to see on websites. I found that all this calculators work on the basis of Latitude and Longitude. So thats in fact air distance between two places like from your home to a shop. Scientifically air distance would be shorter than road distance. A piece of Java code to calculate it :)
import java.lang.Math;
import java.lang.Double;
public int calculateDistance(double latitudeA, double latitudeB, double longitudeA, double longitudeB)
{
double theDistance = (Math.sin(Math.toRadians(latitudeA)) *
Math.sin(Math.toRadians(latitudeB)) +
Math.cos(Math.toRadians(latitudeA)) *
Math.cos(Math.toRadians(latitudeB)) *
Math.cos(Math.toRadians(longitudeA - longitudeB))); // Sin(laA)*Sin(laB) + Cos(laA)*Cos(laB)*Cos(loA-loB)
return = (Math.toDegrees(Math.acos(theDistance))) * 69.09; //
}
No comments:
Post a Comment