在开发中,我们要经常和位置打交道,要计算附近的位置、距离什么的。如下:
一.sql语句
SELECT houseID,title,location,chamber,room,toward,area,rent,is_verify,look_type,look_time,
traffic,block_name,images,tag,create_time,update_time, location->>'$.latitude' AS latitude,
location->>'$.longitude' AS longitude,
(
6371 * acos(
cos(radians(28.6558)) *
cos(radians(CAST(location->>'$.latitude' AS DECIMAL(10, 6)))) *
cos(radians(CAST(location->>'$.longitude' AS DECIMAL(10, 6))) - radians(112.913779)) +
sin(radians(28.6558)) *
sin(radians(CAST(location->>'$.latitude' AS DECIMAL(10, 6))))
)