How to get Distance Kilometer in android?

Posted by user1787493 on Stack Overflow See other posts from Stack Overflow or by user1787493
Published on 2012-11-03T10:57:15Z Indexed on 2012/11/03 11:00 UTC
Read the original article Hit count: 305

i am very new to Google maps i want calculate the distance between two places in android .for that i get the two places lat and lag positions for that i write the following code:

private double getDistance(double lat1, double lat2, double lon1, double lon2) {
               double dLat = Math.toRadians(lat2 - lat1);
                double dLon = Math.toRadians(lon2 - lon1);
                double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                + Math.cos(Math.toRadians(lat1))
                * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
                * Math.sin(dLon / 2);
                double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
                double temp = 6371 * c;
                temp=temp*0.621;
                return temp;
                }

the above code cant give the accurate distance between two places .what is the another way to find distance please give me any suggestions thanks in advance....

© Stack Overflow or respective owner

Related posts about android

Related posts about distance