我要用java写求地球上两点经纬度的距离,重点是还要从表中取数据来计算。。。。大神来帮帮我额
package project;
import java.lang.Math;
public class GLSX {
static double EARTH_RADIUS = 6378.137; /*定义半径 in meters */
static double PI = 3.1415; //定义PI
static double rad(double d)
{
return d * PI/180.0;
}
/*F********************************************************************
Function Name: GlsxGetDistance
Description: It is used to calculate distance between two geographic points.
Thae result is in meter unit.
*********************************************************************F*/
static double Glsxe(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)));
double res = s * EARTH_RADIUS;
return res;
}
public static void main(String[] args)
{
// double g = Glsxe(39.945557,116.266418,39.94548,116.267731);
// System.out.println(g);
}
}
这是部分代码 感兴趣的朋友可以和我联系。。。我们一起完成剩下的部分!
如果能联网的话,用百度API,提供两点的经纬度就可以了