通过经度纬度得到距离
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;
}
通过经度纬度得到距离相关推荐
- 根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)
根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离) 球面上任意两点之间的距离计算公式可以参考维基百科上的下述文章. Great-circle distance Haversine ...
- 函数:GetDistance,计算两个经度纬度之间距离
oracle函数,可以很快捷查出经纬度之间距离 oracle函数代码: CREATE OR REPLACE FUNCTION GetDistance(LngBegin number,LatBegin ...
- 依据经度纬度计算距离方式
MYSQL 计算距离(依据经度纬度) SELECT ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($ilat*PI()/180-lat*PI()/180)/2),2)+COS ...
- 根据经度纬度 筛选距离远近
lon1当前用户经度 lat1当前用户纬度,lon2 sql的经度字段 lat sql的纬度字function distance_sql($lon1,$lat1,$lon2,$lat2) {$sql ...
- java根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)
最近做一个项目:需要查询一个站点(已知该站点经纬度)500米范围内的其它站点.所以,我首先想到的是,对每条记录,去进行遍历,跟数据库中的每一个点进行距离计算,当距离小于500米时,认为匹配.这样做确实 ...
- 根据经度纬度获取距离(km/m)等工具类
计算给定经纬度附近相应公里数的经纬度范围 根据经纬度获取两点之间的距离 打表的方式获取Geohash当前区域周围8个区域编码 设置经纬度转化为geohash长度 RangeUtil: import j ...
- java点到曲线的距离公式,使用Haversine的距离公式获取经度和纬度的距离
我在大熊猫数据框架中工作,我试图获得每个标识符的每个点的经度和纬度的距离 . 这是目前的数据框: Identifier num_pts latitude longitude 0 AL011851 3 ...
- django经度纬度计算两点距离实例及微信商家付款给用户接口实例
长路漫漫,未知作伴. python 根据经度纬度计算两点距离 小数点保留位数 base加时间戳加密 十六进制数字转十进制字符串 微信获取用户openid 云通讯发送短信接口 django 微信小程序提 ...
- 根据经度纬度计算两者之间的距离
$i = 10.0; //差值可自定义,值越大,范围就越大 $min_latitude = $lat - $i; //纬度最小值 $max_latitude = $lat + $i; //纬度最大值 ...
最新文章
- 2021年大数据ELK(十九):使用FileBeat采集Kafka日志到Elasticsearch
- Vulkan Tutorial 12 Fixed functions
- 阿里云云服务器安装jdk、mysql
- Spring Cloud Alibaba基础教程:Sentinel使用Apollo存储规则
- mongodb 简单部署方案及实例
- MySQL整理(三)
- P1313 计算系数(组合数)
- 编程书单:十本Python编程语言的入门书籍
- 洛谷 P1706 P1036 -小试牛刀
- 神舟笔记本触摸板驱动_关闭笔记本触摸板的四种方法
- TensorFlow 教程 --教程--2.1 综述
- 没学过编程可以学python吗_没编程基础可以学python吗
- Leetcode每日一题:42.trapping-rain-water(接雨水)
- 文件分配表(File Allocation Table)入门
- LINUX下载编译libpq(postgresql)
- pycharm运行pytest参数化运行teardown错误
- RGB-D相机原理与选型
- 按拼音首字母排列的地区选择代码 中文和拼音已配好链接
- 大专计算机考试题,大专计算机考试试题.doc
- 创建基于vue的H5