Java計(jì)算兩點(diǎn)之間的距離
/**
* 計(jì)算兩點(diǎn)之間的距離
* @param lonA 經(jīng)度A
* @param latA 緯度A
* @param lonB 經(jīng)度B
* @param latB 緯度B
* @return 兩點(diǎn)之間的距離
*/
public static double countDistance(double lonA,double latA,double lonB,double latB){
SpatialContext geo = SpatialContext.GEO;
double distance = geo.calcDistance(geo.makePoint(lonA, latA), geo.makePoint(lonB, latB)) * DistanceUtils.DEG_TO_KM;
return distance;
}
MySql計(jì)算兩點(diǎn)之間的距離
公式如下客给,單位米:
第一點(diǎn)經(jīng)緯度:lng1 lat1
第二點(diǎn)經(jīng)緯度:lng2 lat2
round(6378.138*2*asin(sqrt(pow(sin( (lat1*pi()/180-lat2*pi()/180)/2),2)+cos(lat1*pi()/180)*cos(lat2*pi()/180)* pow(sin( (lng1*pi()/180-lng2*pi()/180)/2),2)))*1000)
例如:
SELECT store_id,lng,lat, ROUND(6378.138*2*ASIN(SQRT(POW(SIN((22.299439*PI()/180-lat*PI()/180)/2),2)+COS(22.299439*PI()/180)*COS(lat*PI()/180)*POW(SIN((114.173881*PI()/180-lng*PI()/180)/2),2)))*1000) AS juli
FROM store_info
ORDER BY juli DESC
LIMIT 316