C#的写法

public struct EarthPoint
  {
   public const double Ea = 6378137; // 赤道半径 WGS84标准参考椭球中的地球长半径(单位:m) 
   public const double Eb = 6356725; // 极半径  
   public readonly double Longitude,Latidute;
   public readonly double Jd;
   public readonly double Wd;
   public readonly double Ec;
   public readonly double Ed;
   public EarthPoint(double _Longitude,double _Latidute)
   {
    Longitude = _Longitude;
    Latidute = _Latidute;
    Jd = Longitude * Math.PI / 180; //转换成角度
    Wd = Latidute * Math.PI /180; //转换成角度
    Ec = Eb + (Ea - Eb) * (90 - Latidute) / 90;
    Ed = Ec * Math.Cos(Wd);
   }
   public double Distance(EarthPoint _Point)
   {
    double dx = (_Point.Jd - Jd) * Ed;
    double dy = (_Point.Wd - Wd) * Ec;
    return Math.Sqrt(dx * dx + dy *dy);
   }
  }

public static Double GetDistance(double _Longitude1,
   double _Latidute1,
   double _Longitude2,
   double _Latidute2)
  {
   EarthPoint p1 = new EarthPoint(_Longitude1,_Latidute1);
   EarthPoint p2 = new EarthPoint(_Longitude2,_Latidute2);
   return p1.Distance(p2);
  }

C#的写法,可惜不会用,所以将上面的代码改造一下,形成C++的写法

C++的写法:

#include <math.h>
const double Ea = 6378137; // 赤道半径 WGS84标准参考椭球中的地球长半径(单位:m) 
const double Eb = 6356725; // 极半径
#define PI 3.1416926;
class EarthPoint
{
public: 
    double Longitude,Latidute;
    double Jd;
    double Wd;
    double Ec;
    double Ed;

EarthPoint(double _Longitude,double _Latidute)
    {
        Longitude = _Longitude;
        Latidute = _Latidute;
        Jd = Longitude * 3.1415926 / 180; //转换成角度
        Wd = Latidute * 3.1415926 / 180; //转换成角度
        Ec = Eb + (Ea - Eb) * (90 - Latidute) / 90;
        Ed = Ec * cos(Wd);
    }

double Distance(EarthPoint * _Point)
    {
        double dx = (_Point->Jd - Jd) * Ed;
        double dy = (_Point->Wd - Wd) * Ec;
        return sqrt(dx * dx + dy *dy);
    }
};

double GetDistance(double _Longitude1,
                   double _Latidute1,
                   double _Longitude2,
                   double _Latidute2)
{
    EarthPoint *p1 = new EarthPoint(_Longitude1,_Latidute1);
    EarthPoint *p2 = new EarthPoint(_Longitude2,_Latidute2);
    double d=p1->Distance(p2);
    return d;
}

通过经度纬度得到距离相关推荐

  1. 根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)

    根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离) 球面上任意两点之间的距离计算公式可以参考维基百科上的下述文章. Great-circle distance Haversine ...

  2. 函数:GetDistance,计算两个经度纬度之间距离

    oracle函数,可以很快捷查出经纬度之间距离 oracle函数代码: CREATE OR REPLACE FUNCTION GetDistance(LngBegin number,LatBegin ...

  3. 依据经度纬度计算距离方式

    MYSQL 计算距离(依据经度纬度) SELECT ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($ilat*PI()/180-lat*PI()/180)/2),2)+COS ...

  4. 根据经度纬度 筛选距离远近

    lon1当前用户经度 lat1当前用户纬度,lon2 sql的经度字段 lat sql的纬度字function distance_sql($lon1,$lat1,$lon2,$lat2) {$sql ...

  5. java根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)

    最近做一个项目:需要查询一个站点(已知该站点经纬度)500米范围内的其它站点.所以,我首先想到的是,对每条记录,去进行遍历,跟数据库中的每一个点进行距离计算,当距离小于500米时,认为匹配.这样做确实 ...

  6. 根据经度纬度获取距离(km/m)等工具类

    计算给定经纬度附近相应公里数的经纬度范围 根据经纬度获取两点之间的距离 打表的方式获取Geohash当前区域周围8个区域编码 设置经纬度转化为geohash长度 RangeUtil: import j ...

  7. java点到曲线的距离公式,使用Haversine的距离公式获取经度和纬度的距离

    我在大熊猫数据框架中工作,我试图获得每个标识符的每个点的经度和纬度的距离 . 这是目前的数据框: Identifier num_pts latitude longitude 0 AL011851 3 ...

  8. django经度纬度计算两点距离实例及微信商家付款给用户接口实例

    长路漫漫,未知作伴. python 根据经度纬度计算两点距离 小数点保留位数 base加时间戳加密 十六进制数字转十进制字符串 微信获取用户openid 云通讯发送短信接口 django 微信小程序提 ...

  9. 根据经度纬度计算两者之间的距离

    $i = 10.0; //差值可自定义,值越大,范围就越大 $min_latitude = $lat - $i; //纬度最小值 $max_latitude = $lat + $i; //纬度最大值 ...

最新文章

  1. 2021年大数据ELK(十九):使用FileBeat采集Kafka日志到Elasticsearch
  2. Vulkan Tutorial 12 Fixed functions
  3. 阿里云云服务器安装jdk、mysql
  4. Spring Cloud Alibaba基础教程:Sentinel使用Apollo存储规则
  5. mongodb 简单部署方案及实例
  6. MySQL整理(三)
  7. P1313 计算系数(组合数)
  8. 编程书单:十本Python编程语言的入门书籍
  9. 洛谷 P1706 P1036 -小试牛刀
  10. 神舟笔记本触摸板驱动_关闭笔记本触摸板的四种方法
  11. TensorFlow 教程 --教程--2.1 综述
  12. 没学过编程可以学python吗_没编程基础可以学python吗
  13. Leetcode每日一题:42.trapping-rain-water(接雨水)
  14. 文件分配表(File Allocation Table)入门
  15. LINUX下载编译libpq(postgresql)
  16. pycharm运行pytest参数化运行teardown错误
  17. RGB-D相机原理与选型
  18. 按拼音首字母排列的地区选择代码 中文和拼音已配好链接
  19. 大专计算机考试题,大专计算机考试试题.doc
  20. 创建基于vue的H5

热门文章

  1. 快速入门 TensorFlow2 模型部署
  2. 大牛推荐的15本学习数据分析挖掘的好书
  3. Shell下的环境变量
  4. 如何理解Minor/Major/Full GC
  5. MyBatis创建SqlSession-怎么拿到一个SqlSessionTemplate?
  6. 分布式文件系统研究-fastDSF文件上传和下载流程
  7. FileItem API详解及演示
  8. 响应json数据之过滤静态资源
  9. 存储函数和存储过程的区别
  10. 什么是设计模式(Design Patterns)