计算在c#2点之间的距离

编程入门 行业动态 更新时间:2024-10-27 19:24:28
本文介绍了计算在c#2点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图整理出一个方法来计算在C#2点之间的距离。

I am trying to sort out a method to calculate the distance between 2 points in c#.

这是我一直在努力了代码,虽然我担心的答案我,得到的是不正确的。

This is the code I have been trying though I fear the answer I get is not correct.

static void Main() { //postcode australia 2600 -> 3000 float latA = -31.997976f; float longA = 115.762877f; float latB = -31.99212f; float longB = 115.763228f; decimal distance = (DistanceBetween(latA, latB, longA, longB)); Console.WriteLine("Distance is" + distance); Console.ReadLine(); } static decimal DistanceBetween(float latA, float longA, float latB, float longB) { var RadianLatA = Math.PI * latA / 180; var RadianLatb = Math.PI * latB / 180; var RadianLongA = Math.PI * longA / 180; var RadianLongB = Math.PI * longB / 180; double theDistance = (Math.Sin(RadianLatA)) * Math.Sin(RadianLatb) + Math.Cos(RadianLatA) * Math.Cos(RadianLatb) * Math.Cos(RadianLongA - RadianLongB); return Convert.ToDecimal(((Math.Acos(theDistance) * (180.0 / Math.PI)))) * 69.09M * 1.6093M; }

这是从本网站找到这里的响应适应 地址之间的距离

this was adapted from a response found on this site here Distance between addresses

这是什么有什么想法脚麻/

Any thoughts on what is going wrong/

由于瑞安

推荐答案

的Ⅰ类一般用的是会有地理座标

double latA = -31.997976f; double longA = 115.762877f; double latB = -31.99212f; double longB = 115.763228f; var locA = new GeoCoordinate(latA, longA); var locB = new GeoCoordinate(latB, longB); double distance = locA.GetDistanceTo(locB ); // metres

更多推荐

计算在c#2点之间的距离

本文发布于:2023-10-27 22:32:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534742.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!