get distance geolocation given latitude and longitude ASP .net c#

Posted: February 8, 2012 in web

This will return in miles.

    public static double ConvertDegreesToRadians(double degrees)
    {
        double radians = (Math.PI / 180) * degrees;
        return radians;
    }
    public static double getDistanceGeneric(double Lat, double Lng, double currentLat, double currentLng)
    {
        double d = (3959 * Math.Acos(Math.Cos(ConvertDegreesToRadians(currentLat)) * Math.Cos(Lib.ConvertDegreesToRadians(Convert.ToDouble(Lat))) * Math.Cos(Lib.ConvertDegreesToRadians(Convert.ToDouble(Lng)) - Lib.ConvertDegreesToRadians(currentLng)) + Math.Sin(Lib.ConvertDegreesToRadians(currentLat)) * Math.Sin(Lib.ConvertDegreesToRadians(Convert.ToDouble(Lat)))));
        return d;
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s