获取地球上两经纬度坐标点间的距离,利用【大圆距离公式】

 

A diagram illustrating great-circle distance (drawn in red) between two points on a sphere, P and Q. Two antipodal points, u and v, are also depicted.

谷歌都在用呢, C#实现的代码如下:

 /// <summary>
/// 地球半径
/// </summary>
private const double EARTH_RADIUS = 6378.137;
/// <summary>
/// 获取两点之间的距离,大圆距离公式
/// </summary>
/// <param name="lat1"></param>
/// <param name="lon1"></param>
/// <param name="lat2"></param>
/// <param name="lon2"></param>
/// <returns></returns>
public static double DistanceOfEarthTwoPoints(double latA, double lngA, double latB, double lngB) {
double radLat1 = lat1 * Math.PI / 180.0;
     double radLat2 = lat2 * Math.PI / 180.0;
     double a = radLat1 - radLat2;
     double b = lon1 * Math.PI / 180.0 - lon2 * Math.PI / 180.0;
     double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
     s = s * EARTH_RADIUS;
     s = Math.Round(s * 1000000) / 1000000;
     return s;
}

当然还有另一种写法:

/// <summary>
/// 获取两点之间的距离,大圆距离公式
/// </summary>
/// <param name="lat1"></param>
/// <param name="lon1"></param>
/// <param name="lat2"></param>
/// <param name="lon2"></param>
/// <returns></returns>
public static double DistanceOfEarthTwoPoints(double latA, double lngA, double latB, double lngB) {
double s = Math.Acos(Math.Cos(Rad(latA)) * Math.Cos(Rad(latB)) * (Math.Cos(Rad(lngA) - Rad(lngB))) + Math.Sin(Rad(latA)) * Math.Sin(Rad(latB)));
s = s * EARTH_RADIUS;
s = Math.Round(s * ) / ;
return s;
}

其实这两个方法是完全等价的,只是化简程序不同而已,看看下面的解释:

Formulas

 
An illustration of the central angle, Δσ, between two points, P and Q. λ and φ are the longitudinal and latitudinal angles of P respectively

Let and be the geographical latitude and longitude of two points 1 and 2, and their absolute differences; then , the central angle between them, is given by the spherical law of cosines:

The distance d, i.e. the arc length, for a sphere of radius r and given in radians

Computational formulas

On computer systems with low floating-point precision, the spherical law of cosines formula can have large rounding errors if the distance is small (if the two points are a kilometer apart on the surface of the Earth, the cosine of the central angle comes out 0.99999999). For modern 64-bit floating-point numbers, the spherical law of cosines formula, given above, does not have serious rounding errors for distances larger than a few meters on the surface of the Earth.[2] The haversine formula is numerically better-conditioned for small distances:[3]

Historically, the use of this formula was simplified by the availability of tables for the haversine function: hav(θ) = sin2(θ/2).

Although this formula is accurate for most distances on a sphere, it too suffers from rounding errors for the special (and somewhat unusual) case of antipodal points (on opposite ends of the sphere). A more complicated formula that is accurate for all distances is the following special case of the Vincenty formula for an ellipsoid with equal major and minor axes:[4]

When programming a computer, one should use the atan2() function rather than the ordinary arctangent function (atan()), so that is placed in the correct quadrant.

The determination of the great-circle distance is just part of the more general problem of great-circle navigation, which also computes the azimuths at the end points and intermediate way-points.

C# JackLib系列之如何获取地球上两经纬度坐标点间的距离的更多相关文章

  1. 计算地球上两个坐标点(经度,纬度)之间距离sql函数

    go --计算地球上两个坐标点(经度,纬度)之间距离sql函数 --作者:lordbaby --整理:www.aspbc.com CREATE FUNCTION [dbo].[fnGetDistanc ...

  2. 获取经纬度之间两点间真实距离(适用于GoogleMap,BaiduMap,Amap等)

    如何获取经纬度之间两点间真实距离(适用于GoogleMap,BaiduMap,Amap等)  目标:使用百度定位sdk开发实时移动距离计算功能,根据经纬度的定位,计算行驶公里数并实时刷新界面显示.大家 ...

  3. php根据地球上任意两点的经纬度计算两点间的距离 原理

    地球是一个近乎标准的椭球体,它的赤道半径为6378.140千米,极半径为6356.755千米,平均半径6371.004千米.如果我们假设地球是一个完美的球体,那么它的半径就是地球的平均半径,记为R.如 ...

  4. C# 获取两点(经纬度表示)间的距离

    #region 获取两点(经纬度表示)间的距离 /// <summary> /// 获取两点(经纬度表示)间的距离 /// </summary> /// <param n ...

  5. 用户Ip地址和百度地图api接口获取用户地理位置(经纬度坐标,城市)

    <?php   //获取用户ip(外网ip 服务器上可以获取用户外网Ip 本机ip地址只能获取127.0.0.1) function getip(){     if(!empty($_SERVE ...

  6. matlab练习程序(地图上画经纬度)

    需要看下生成的数据在地球上的经纬度具体位置. 投影为墨卡托投影.   clear all; close all; clc; load coast; a=load('out.txt'); %自己的经纬度 ...

  7. C#开发BIMFACE系列8 服务端API之获取文件上传状态信息

    系列目录     [已更新最新开发文章,点击查看详细] 在BIMFACE控制台上传文件,上传过程及结束后它会自动告诉你文件的上传状态,目前有三种状态:uploading,success,failure ...

  8. Hadoop系列004-Hadoop运行模式(上)

    title: Hadoop系列004-Hadoop运行模式(上) date: 2018-11-20 14:27:00 updated: 2018-11-20 14:27:00 categories: ...

  9. 【ABAP系列】SAP 获取工单和工序的状态

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 获取工单和工序的状态   ...

随机推荐

  1. 多线程-NSOperation中使用ASIHttpRequest注意事项

    最近做的iPhone项目中有一如下功能: app在用户许可后将本地Photos的照片上传到服务器,期间用户可以做其他任何操作,等上传成功后弹出一个toast通知用户. 原先的代码结构是: 获取照片的操 ...

  2. cURL: PHP并发处理方式

    function classic_curl($urls, $delay) { $queue = curl_multi_init(); $map = array(); foreach ($urls as ...

  3. 【转】DB2 常用命令

    1. 打开命令行窗口  #db2cmd 2. 打开控制中心  # db2cmd db2cc 3. 打开命令编辑器  db2cmd db2ce =====操作数据库命令===== 4. 启动数据库实例  ...

  4. 【Android】跟着教程做の学习笔记

    教程 + <第一行代码 - Android> //尽量在十二月底学完吧(同步学习java基础)

  5. order by多个字段对索引的影响

    某前台sql语句,简化后如下SELECT products_name,products_viewed FROM `products_description` ORDER BY products_vie ...

  6. Intent七大属性

    一.Intent的作用是什么?    1.Intent 用于封装程序的”调用意图“.两个Activity之间,可以把需要交换的数据封装成Bundle对象,然后使用Intent携带Bundle对象,实现 ...

  7. JSON和JSONP有哪些区别,PhoneGap跨域请求如何实现

    前言 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socke ...

  8. 所有 HTTP 状态代码及其定义

    所有 HTTP 状态代码及其定义. 代码  指示  2xx  成功  200  正常:请求已完成.  201  正常:紧接 POST 命令.  202  正常:已接受用于处理,但处理尚未完成.  20 ...

  9. Linux下的Memcache安装

    Linux下Memcache服务器端的安装服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.3.0 .下载:http://www.danga.com/memcach ...

  10. Linux中用stat命令查看文件时3个时间点解析

    有些时候,我们需要在Linux中使用stat命令来查看文件的详细信息.另外联想下,ls -l命令显示的是什么时间,touch命令修改文件的时间戳,修改的又是什么时间?在这里我们一起来试验下. 首先,我 ...