显示距离路线 5 公里处的所有标记

Show all markers placed at 5km distance from route

在我的应用程序中,我显示了 A 点到 B 点之间的路线。

final PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(mContext, R.color.accent_color));
polyOptions.width(20);
polyOptions.addAll(currentRoute.getPoints());

在currentRoute.getPoints中,我拥有所有用于在地图上绘制路线的LatLng。我将所有距离为 5km 的点提取到名为 points 的 ListArray 中。

现在我想沿着这条路线填充我数据库中的位置。我需要显示我的数据库中在 5 公里限制范围内(在路线两侧)在路线上或附近的所有位置。

为此,我需要转到数据库并过滤记录以查找 5 公里范围内的所有位置。我不知道如何实现 location_latitude 和 location_longitude 的 WHERE 请求,以获取参考位置 5 公里范围内的所有记录。

我目前的SQL是:

query = "SELECT location_id, location_name, " +
                "location_address, location_image, " +
                "location_latitude, location_longitude, " +
                "c.category_marker, l.category_id " +
                "FROM tbl_categories c, tbl_locations l " +
                "WHERE l.category_id " + " = " + categ + " AND l.category_id = c.category_id AND " +
                "location_county " + " =  \"" + county + "\"";

有什么建议可以更快地过滤我的数据库(sql 查询)以查找路线附近的所有位置吗?

我是这样走的:

 where_query = new StringBuilder();
        for (i = 0; i <= points.size()-1 ; i ++) {
            if (i == 0) {
                where_query.append(" AND ((location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
            } else {
                if (i < points.size() - 1) {
                    where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
                } else {
                    where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append("))");
                }
            }
        }

等待建议!