百度地图MySQL如何实现按距离排序、范围查找
2022-05-29 本文已影响0人
CentForever
表结构如下:
-- ----------------------------
-- Table structure for sblocation_table
-- ----------------------------
DROP TABLE IF EXISTS "sblocation_table";
CREATE TABLE "sblocation_table" (
"_id" TEXT,
"address" TEXT,
"lon" REAL,
"createtime" TEXT,
"longitude" TEXT,
"latitude" TEXT,
"lat" REAL,
"type" TEXT,
"owner" TEXT,
PRIMARY KEY ("_id")
);

SELECT DISTINCT
sblocation_table._id,
sblocation_table.address,
sblocation_table.createtime,
sblocation_table.longitude,
sblocation_table.latitude,
sblocation_table.owner,
ROUND(
6378.138 * 2 * ASIN (
SQRT (
POW ( SIN ( ( 34.200317 * PI () / 180 - latitude * PI () / 180 ) / 2 ), 2 ) + COS ( 34.200317 * PI () / 180 ) * COS ( latitude * PI () / 180 ) * POW ( SIN ( ( 108.875249 * PI () / 180 - longitude * PI () / 180 ) / 2 ), 2 )
)
) * 1000
) AS distance_um
FROM
sblocation_table
ORDER BY
distance_um ASC
34.200317 108.875249为输入值

在Android SqlLite上执行错误
