分类:
2010-09-13 12:14:46
/** * 计算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; } 获得两点间的GPS距离文章分类:移动开发在android中可采用如下代码获取距离:
在其他设备若没有类似android的Location的distanceBetween方法开采用如下代码获取:
这个计算得出的结果是英里,如果要转换成公里,需要乘以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
private const double EARTH_RADIUS = 6378.137; |
chinaunix网友2010-09-13 22:07:32
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com