我知道如何从最近的区域获取物体:
db.execSQL("CREATE TABLE Task ("
+ "id smallint(6) NOT NULL,"
+ "project_id smallint(6) NOT NULL,"
+ "add_date varchar(15) NOT NULL,"
+ "geo_lat double NOT NULL,"
+ "geo_long double NOT NULL,"
+ "additional_info TEXT NULL" + ");");
和
"SELECT * FROM Task WHERE (geo_lat BETWEEN " + lat_bot + " AND " + lat_top + ") AND (geo_long" + " BETWEEN " + long_bot + " AND " + long_top + ")"
但我的问题是如何按最接近的顺序排序?
答案 0 :(得分:0)
您应该按照您所在地区的DISTANCE对物体进行排序。以下公式非常复杂,可以构建在Application layer
上,而不是sql
。
供您参考。使用'hasrsine'公式计算两点之间的大圆距离:
Haversine: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
formula: c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c
其中φ是纬度,λ是经度,R是地球半径(平均半径= 6,371km); 请注意,角度需要以弧度为单位才能传递给trig函数!
参考:Calculate distance, bearing and more between Latitude/Longitude points