首页 > 编程语言 >[C#] 计算两点(经纬度)的距离

[C#] 计算两点(经纬度)的距离

时间:2023-04-21 15:22:50浏览次数:28  
标签:Rad 经纬度 C# double 经度 两点 2.0 Math

 1 /// <summary>
 2 /// 经纬度转换为弧度
 3 /// </summary>
 4 /// <param name="d">经度/纬度</param>
 5 /// <returns></returns>
 6 private static double Rad(double d)
 7 {
 8      return d * Math.PI / 180.0;
 9 }
10 /// <summary>
11 /// 计算两点之间的距离,单位公里
12 /// </summary>
13 /// <param name="lat1">第一点经度</param>
14 /// <param name="lng1">第一点纬度</param>
15 /// <param name="lat2">第二点经度</param>
16 /// <param name="lng2">第二点纬度</param>
17 /// <returns></returns>
18 public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
19 {
20     double num1 = Rad(lat1) - Rad(lat2);
21     double num2 = Rad(lng1) - Rad(lng2);
22     return Math.Round(2.0 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(num1 / 2.0), 2.0) + Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0))) * (以公里为单位的地球半径) * 10000.0) / 10000.0;
23 }

 

标签:Rad,经纬度,C#,double,经度,两点,2.0,Math
From: https://www.cnblogs.com/wynblogscc/p/17340443.html

相关文章

  • Excel的列数如何用数字表示?
      本文介绍在Excel表格文件中,用数字而非字母来表示列号的方法。  在日常生活、工作中,我们不免经常使用各种、各类Excel表格文件;而在Excel表格文件中,微软Office是默认用数字表示行数,用字母表示列数的,如下图所示:  而这样就带来一个问题:当一个Excel表格文件的列数相对较多时......
  • react 生命周期钩子函数
    1、挂载:construct、getDerivedStateFromProps、render、componentDidMounted2、更新:getDerivedStateFromProps、componentWillUpdate、render、getSnapshotBeforeUpdate、componentDidUpdated3、卸载:componentWillUnmounted4、请求放在componentDidMount里react生命周期图:h......
  • tomcat提示静态文件缓存超限,造成日志爆满的问题
    日志片段:21-Apr-202311:20:47.215警告[http-nio-80-exec-5308]org.apache.catalina.webresources.Cache.getResourceUnabletoaddtheresourceat[/FileUploads/www/site/2022/11/30/ZZVRQAHD08ZX4GOW47.jpg]tothecacheforwebapplication[]becausetherewasin......
  • Oracle删除用户及用户下的全部数据
     1、查看用户select*fromall_usersselect*fromuser_usersselect*fromdba_users2、查看用户的连接状况selectusername,sid,serial#fromv$sessionwhereusername='NCC'3、找到要删除用户的sid,和serial,并删除altersystemkillsession'4521,27770'4......
  • SpringCloud集成dubbo的使用
    1.生产者(服务提供者)操作。(服务提供者方的配置)(1)添加依赖(我这里的版本是2.2.3RELEASE)<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId></dependency>(2)提供统一业务api (建议api层和实现层分为两个模块)pub......
  • react ref
    一、使用ref操作DOM1、要访问由React管理的DOM节点,首先,引入useRefHook:import{useRef}from'react';2、然后,在你的组件中使用它声明一个ref:constmyRef=useRef(null);3、最后,将其作为ref属性传给DOM节点:<divref={myRef}>总结:useRefHook......
  • grafana仪表盘的数据报错unexpected character: ‘\ufeff’”
    grafana仪表盘的数据拷贝展示后,出现报错:Parseerroratchar4:unexpectedcharacter:‘\ufeff’”报错时点击编辑仪表盘,发现没有什么异常的地方:这时可以点击jsons数据来查看是否存在了些特殊的不可见字符这里面一些不可见字符或者或展示出来,删除即可这是低版本的一个bug......
  • C# 设置Menustrip提示框的显示 -转载
    设置Menustrip提示框的显示:(1)先在Menustrip的属性中对【ShowItemToolTips】的属性进行设置,设置为true代表要显示提示框,如下图设置: (2)设置ToolStripMenuItem的【AutoToolTip】属性,设置为true代表要显示提示框,如下图设置: (3)设置ToolStripMenuItem的【ToolTipText】属性,设置提示......
  • C++11之std::future对象的基本用法
    1、//futureexample#include<iostream>//std::cout#include<future>//std::async,std::future#include<chrono>//std::chrono::milliseconds//anon-optimizedwayofcheckingforprimenumbers:boolis_prime......
  • centos 常用命令
    centos常用命令批量删除进程ps-ef|grepmongo|grep-v"grep"|awk'{print$2}'|xargskill-9grep-v这个参数的作用是排除某个字符。所以这里排除了grep的命令。之后也利用awk找到pid这一列。最后的xargs是从标准输出获取参数并执行命令的程序,即从前面的命令获......