Measure the current search first
A slow map does not immediately call for a Quadtree. Separate list filtering, distance calculations, marker creation, and tile loading to find the cost. Index construction and memory also have a price.
This is a decision procedure and a small example. It does not claim that deployed BAKUO uses Quadtree or Geohash. Finding related local source code cannot establish a measured improvement for real visitors.
Select candidates with a box
Start with a reference function that selects points inside a visible rectangle. This example scans the whole array. A simple baseline helps detect missing points when a faster implementation is added.
function selectBox(points, box) {
const { south, north, west, east } = box;
if (![south, north, west, east].every(Number.isFinite)) {
throw new TypeError('Box edges must be numbers');
}
if (south < -90 || north > 90 || west < -180 || east > 180
|| south > north || west > east) {
throw new RangeError('Expected a non-wrapping geographic box');
}
return points.filter(point => {
if (!Number.isFinite(point.lat) || !Number.isFinite(point.lng)
|| Math.abs(point.lat) > 90 || Math.abs(point.lng) > 180) {
throw new TypeError('Invalid point');
}
return point.lat >= south && point.lat <= north
&& point.lng >= west && point.lng <= east;
});
}
const points = [
{ id: 'inside', lat: 37.5, lng: 127 },
{ id: 'edge', lat: 37, lng: 126 },
{ id: 'outside', lat: 38.5, lng: 127 }
];
const box = { south: 37, north: 38, west: 126, east: 128 };
console.log(selectBox(points, box).map(point => point.id));
// [ 'inside', 'edge' ]Run it in a browser console or Node.js: it returns inside and edge. The comparisons explicitly include the boundary. These are synthetic points, not stores. Boxes crossing the antimeridian are outside this example’s contract.
A rectangle is not a radius
Selecting the visible map rectangle and finding points within a radius are different questions. A rectangle around a circle also includes its corners. For a circular search, perform a final distance check.
A possible sequence is candidate selection, distance calculation, radius filtering, then sorting. Zero can be a meaningful radius. Decide whether the product accepts it instead of silently replacing it with a default.
Compare grids and Quadtrees
A fixed grid is straightforward but needs a cell size. Tiny cells mean visiting many cells; large cells leave many candidates. Geohash-prefix searches also need neighbouring cells and boundary handling to avoid missing nearby points.
A Quadtree subdivides an area recursively. Clustered points and frequent data updates affect construction and maintenance costs. Neither approach wins from its description alone. Compare against a simple scan using the actual distribution.
Check results before claiming an improvement
- Measure initial loading and index construction separately from query time.
- Compare result ID sets in dense areas, empty areas, and on boundaries.
- After an update, check that deleted points disappear and new points appear.
- Include marker rendering and memory usage when assessing the screen response.
If a faster implementation disagrees with the reference, resolve correctness first. Publish only measurements accompanied by device, browser, dataset, and query conditions.