-- Hive计算两个经纬度坐标直线距离(单位:公里)
-- 公式
-- ASIN(
-- SQRT(
-- POWER(SIN((lat1-lat2)*ACOS(-1)/360),2) +
-- COS(lat1*ACOS(-1)/180)*COS(lat2*ACOS(-1)/180)
-- *POWER(SIN((lon1-lon2)*ACOS(-1)/360),2)
-- )
-- )*6378137*2/1000 as distance
-- example
select
-- exam1(人民广场/东方明珠广播电视塔,121.481318,31.235056/121.506379,31.245414)
ASIN(
SQRT(
POWER(SIN((31.235056-31.245414)*ACOS(-1)/360),2) +
COS(31.235056*ACOS(-1)/180)*COS(31.245414*ACOS(-1)/180)
*POWER(SIN((121.481318-121.506379)*ACOS(-1)/360),2)
)
) *6378137*2/1000 as distance1
-- exam2(上海虹桥国际机场/上海浦东国际机场,121.346817,31.203347/121.81509,31.157478)
,
ASIN(
SQRT(
POWER(SIN((31.203347-31.157478)*ACOS(-1)/360),2) +
COS(31.203347*ACOS(-1)/180)*COS(31.157478*ACOS(-1)/180)
*POWER(SIN((121.346817-121.81509)*ACOS(-1)/360),2)
)
) *6378137*2/1000 as distance2