SELECT
eden_product.product_number,
(
6371 * acos(
cos(radians( 31.398876 )) * cos(radians( product_adress_y )) *
cos(radians( product_adress_x ) - radians(121.467962 )) +
sin(radians( 31.398876 )) * sin(radians( product_adress_y ))
)) AS distance
FROM
eden_product
WHERE
product_adress_x IS NOT NULL
ORDER BY
distance
LIMIT 0,
1
product_adress_y 是数据库的纬度
product_adress_x 是数据库的经度
给定一个经纬度,查找数据库离这个给定的经纬度最近的目标
注意,这里数据参数 31.398876 是纬度 ,121.467962 是经度 eden_product为查找的目标