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
latitude
B, double longitudeA, double
longitude
B)
{
double theDistance = (Math.sin(Math.toRadians(
latitude
A)) *
Math.sin(Math.toRadians(
latitude
B)) +
Math.cos(Math.toRadians(
latitude
A)) *
Math.cos(Math.toRadians(
latitude
B)) *
Math.cos(Math.toRadians(
longitude
A -
longitude
B))); // Sin(laA)*Sin(laB) + Cos(laA)*Cos(laB)*Cos(loA-loB)
return = (Math.toDegrees(Math.acos(theDistance))) * 69.09; //
}
No comments:
Post a Comment