C# Calculate the distance function between two points with known longitude and latitude

黄舟
Release: 2017-02-28 11:12:34
Original
2343 people have browsed it


C# Calculate the distance function between two points with known longitude and latitude

public Task<double> GetDistance(double lat1, double lon1, double lat2, double lon2)
        {
            int R = 6371;


            double rLat1 = ToRadian(lat1);
            double rLat2 = ToRadian(lat2);


            double dLat = rLat2 - rLat1;
            double dLon = ToRadian(lon2 - lon1);


            double a = Math.Pow(Math.Sin(dLat / 2), 2) +
                Math.Pow(Math.Sin(dLon / 2), 2) *
                Math.Cos(rLat1) * Math.Cos(rLat2);


            double b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));


            return Task.FromResult((R * b));
        }
Copy after login

The above is the content of C# Calculate the distance function between two points with known longitude and latitude. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!