这是我一直用来为具有存储在数据库中的 GPS 数据的对象获取排序子句的方法:
public String getOrderString(double latitude, double longitude) {
double fudge = Math.pow(Math.cos(Math.toRadians(latitude)), 2);
return "((" + latitude + " - " + KEY_LATITUDE + ") * (" + latitude
+ " - " + KEY_LATITUDE + ") + (" + longitude + " - "
+ KEY_LONGITUDE + ") * (" + longitude + " - " + KEY_LONGITUDE
+ ") * " + fudge + ") ASC";
}
从here'借来的'。我对软糖因素的理解是它考虑了不在赤道附近的坐标。到目前为止,这个方程对我来说效果很好,而且相当快。
现在,我认为您可以通过执行以下操作来利用相同的方程式:
public String getWhereString(double latitude, double longitude, double threshold) {
double fudge = Math.pow(Math.cos(Math.toRadians(latitude)), 2);
return "((" + latitude + " - " + KEY_LATITUDE + ") * (" + latitude
+ " - " + KEY_LATITUDE + ") + (" + longitude + " - "
+ KEY_LONGITUDE + ") * (" + longitude + " - " + KEY_LONGITUDE
+ ") * " + fudge + ") < " + threshold;
}
那么你的删除方法是这样的:
public int removeBuildingEntry(double latitude, double longitude, double threshold) {
String where = getWhereString(double latitude, double longitude, double threshold)
return db.delete(TABLE, where, null);
}
唯一的问题是我不知道方程结果的单位,因此你应该传入什么作为阈值。在我的情况下,我不关心那些,因为我只想要订单,但在你的情况下,这可能会有所作为。如果需要更准确的数字,您可以尝试使用不同的值或尝试计算它。