已知兩點經緯度求距離
阿新 • • 發佈:2019-02-05
package com.chx.finddata.JdbcUtils;import com.chx.finddata.domain.Data;import com.chx.finddata.domain.RePoint;/** * 已知經緯度計算距離 * @author xh * */public class Distance {public static double GetDistance(Data tp, RePoint rp){double PI = 3.1415926;double Earth_Radius
= 6378137; // 地球半徑,單位:米double Lat1 = (double)tp.getLatitude();double Lat2 = (double)rp.getLatitude();double a=(double)tp.getLongitude()-(double)rp.getLongitude();double s=Math.acos(Math.sin(Lat1)*Math.sin(Lat2)+Math.cos(Lat1)*Math.cos(Lat2)*Math.cos(a));double
d=s*PI*Earth_Radius/180;// System.out.println(d);return d;}}已經在專案中使用了,還比較準確