[android-developers] Gettting Defferent Distance When Using the Google Map and User defined Function
I want to get the Distance between two latitude and longitude in
meter / km . So i am using the below function . It gives me the
different result than the google Map.
Can you help me to solve my problem ? i dont understand What is the
Problem ?
Code
private double distance(double lat1, double lon1, double lat2, double
lon2)
{
double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1)) *
Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) *
Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
return (dist);
}
private double deg2rad(double deg)
{
return (deg * Math.PI / 180.0);
}
private double rad2deg(double rad)
{
return (rad * 180.0 / Math.PI);
}
Current Latitude = 23.012281666666663 Current Longitude =
72.51798333333333
Destination Latitude = 23.1120487 Destination Latitude = 72.5766759
It gives this Result = 12579.679 in Meter, while in google map it
gives this result = 17.9 Km
I do not understand why this two gives the different result.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home