/**
     * 计算GPS两点间的距离[单位为:米]
     * @param center GPS当前数据(LonLat对象表示,LonLat.lon表示经度,LonLat.lat表示纬度)
     * @param turnPoint 转向点经纬度对象
     * @return
     */
    private double gpsDistance( LonLat center, LonLat turnPoint )
    {
        double distance = 0;
        double lonRes = 102900, latRes = 110000;
       
distance = Math.sqrt( Math.abs( center.lat - turnPoint.lat ) * latRes *
Math.abs( center.lat - turnPoint.lat ) * latRes +
                Math.abs( center.lon - turnPoint.lon ) * lonRes * Math.abs( center.lon - turnPoint.lon ) * lonRes );
//        System.out.println( "两点间距离:" + distance );
        return distance;
    }
 
 

在android中可采用如下代码获取距离:

  1. public double getDistance(double lat1, double lon1, double lat2, double lon2) {
  2. float[] results=new float[1];
  3. Location.distanceBetween(lat1, lon1, lat2, lon2, results);
  4. return results[0];
  5. }

在其他设备若没有类似android的Location的distanceBetween方法开采用如下代码获取:

  1. double distance(double lat1, double lon1, double lat2, double lon2) {
  2. double theta = lon1 - lon2;
  3. double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
  4. + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
  5. * Math.cos(deg2rad(theta));
  6. dist = Math.acos(dist);
  7. dist = rad2deg(dist);
  8. double miles = dist * 60 * 1.1515;
  9. return miles;
  10. }
  11. //将角度转换为弧度
  12. static double deg2rad(double degree) {
  13. return degree / 180 * Math.PI;
  14. }
  15. //将弧度转换为角度
  16. static double rad2deg(double radian) {
  17. return radian * 180 / Math.PI;
  18. }

这个计算得出的结果是英里,如果要转换成公里,需要乘以1.609344,若是海里需要乘以0.8684

http://alex-yang-xiansoftware-com.javaeye.com/blog/649462

用于GPS换算世界上任意两点间距离

        /// 
        /// 计算地球上任意两点距离
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 返回长度单位是米
        private static double Distance(double long1, double lat1, double long2, double lat2)
        {
            double a, b, R;
            R = 6378137; //地球半径
            lat1 = lat1 * Math.PI / 180.0;
            lat2 = lat2 * Math.PI / 180.0;
            a = lat1 - lat2;
            b = (long1 - long2) * Math.PI / 180.0;
            double d;
            double sa2, sb2;
            sa2 = Math.Sin(a / 2.0);
            sb2 = Math.Sin(b / 2.0);
            d = 2 * R * Math.Asin(Math.Sqrt(sa2 * sa2 + Math.Cos(lat1) * Math.Cos(lat2) * sb2 * sb2));
            return d;
        }

---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian

http://www.blogjava.net/TiGERTiAN/archive/2010/05/01/319853.html

从google maps的脚本里扒了段代码,是用来计算两点间经纬度距离

private const double EARTH_RADIUS = 6378.137;
private static double rad(double d)
{
  return d * Math.PI / 180.0;
}

public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
  double radLat1 = rad(lat1);
  double radLat2 = rad(lat2);
  double a = radLat1 - radLat2;
  double b = rad(lng1) - rad(lng2);
  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 * 10000) / 10000;
  return s;
}

计算GPS两点间的距离[单位为:米]的更多相关文章

  1. TSQL 根据经纬度计算两点间的距离;返回米(m)

    -- ============================================= -- Author:Forrest -- Create date: 2013-07-16 -- Des ...

  2. HDOJ2001计算两点间的距离

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. J - 计算两点间的距离

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 输入两 ...

  4. 计算两点间的距离-hdu2001

    Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.   Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2 ...

  5. 计算两点间的距离,hdu-2001

    计算两点间的距离 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.   Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1 ...

  6. HDU 2001 计算两点间的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=2001 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离 ...

  7. hdu2001 计算两点间的距离【C++】

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. 计算地图上两点间的距离PHP类

    计算地图上两点间的距离,使用的是谷歌地图 <?php class GeoHelper { /** * @param int $lat1 * @param int $lon1 * @param i ...

  9. 已知两点的经度和纬度,计算两点间的距离(php,javascript)

    php代码:转载 http://www.cnblogs.com/caichenghui/p/5977431.html /** * 求两个已知经纬度之间的距离,单位为米 * * @param lng1 ...

随机推荐

  1. Rust安装配置

    Rust安装配置 话说前面: 如果你 之前安装过老版本的 rust 请先卸载 我说的是以 msi 文件安装的那种, 请进控制面板–> 程序中进行卸载 首先 下载官网 的 rustup-init. ...

  2. REST Web 服务(一)----REST 介绍

    1. 什么是REST? REST 定义了一组体系架构原则,您可以根据这些原则设计以系统资源为中心的 Web 服务,包括使用不同语言编写的客户端如何通过 HTTP 处理和传输资源状态. 2. REST的 ...

  3. 【CF Round 439 C. The Intriguing Obsession】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. macOS Sierra下如何打开任何来源(10.12系统)

    转载声明:本站文章无特别说明皆为原创,转载请注明:史蒂芬周的博客, 一定有很多朋友和小子一样,迫不及待的升级到了macOS Sierra,随之而来的是第三方应用都无法打开了,提示无法打开或者扔进废纸篓 ...

  5. Codeforces 934.A A Compatible Pair

    A. A Compatible Pair time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. hdu 6114 百度之星复赛B T1

    Chess Problem Description 車是中国象棋中的一种棋子,它能攻击同一行或同一列中没有其他棋子阻隔的棋子. 一天,小度在棋盘上摆起了许多車……他想知道,在一共N×M个点的矩形棋盘中 ...

  7. 创建型设计模式之单例模式(Singleton)

     结构 意图 保证一个类仅有一个实例,并提供一个访问它的全局访问点. 适用性 当类只能有一个实例而且客户可以从一个众所周知的访问点访问它时. 当这个唯一实例应该是通过子类化可扩展的,并且客户应该无需更 ...

  8. [bzoj1833][ZJOI2010]count 数字计数——数位dp

    题目: (传送门)[http://www.lydsy.com/JudgeOnline/problem.php?id=1833] 题解: 第一次接触数位dp,真的是恶心. 首先翻阅了很多很多一维dp,因 ...

  9. Java设计模式_创建型模式_单例模式

    单例模式的实现: 定义一个类,在类中定义该类的静态变量,再定一个一个获取该类的静态变量的方法. UML图:

  10. vboxmanage查询正在运行的vbox虚拟机

    系统:linux通用,virtualbox5.0 每次用下面命令启动vm虚拟机时,发现没办法知道它的IP. $ vboxmanage startvm <vmname> --type hea ...