Monday, October 22, 2012

Calculate Distance between two location (GeoPoint)

public double CalculationByDistance(Location Start, Location End)
{
        double Radius = 6371;
        double lat1 = Start.getLatitude();
        double lat2 = End.getLatitude();
        double lon1 = Start.getLongitude();
        double lon2 = End.getLongitude();
        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 km = Radius * c;
        return km * 1000;
}

2 comments:

Abdul bari said...

distance between two cities of India? Take the help of the city distance search engine. The search engine helps in finding the distance between major cities.

Saniya Binal said...

Now you can calculate Distance Between Two Places with the help of distance calculator site are google map.