September 8th, 2011, 06:20 AM
|
#1 (permalink)
|
|
Junior Member
Join Date: Jul 2011
Posts: 27
Device(s):
Thanks: 9
Thanked 2 Times in 2 Posts
|
Find the distance between 2 Latitudes and Longitudes ?
Hi,
Below is the code to find distance between 2 Latitudes and Longitudes. But it is not working proper way.
////////////////////////////////
public double lanLatDistance(double oldlan, double oldlat,
double plan, double plat) {
double R = 6371; // earth’s radius (mean radius = 6,371km)
double dLat = Math.toRadians(oldlan - plan);
double dLon = Math.toRadians(oldlat - plat);
double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) +
(Math.cos(Math.toRadians(oldlan)) * Math.cos(Math.toRadians(plan)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double distance = R * c;
//System.out.println("distance" + distance);
return distance;
}
///////////////////////////////
Please help me to find out where I am doing mistake.
Please mention in the piece of codes.
Thanks and Regards,
Andy
|
|
|