v157 · approximate geolocation

Store locator that asks for less

The usual reason a site asks for precise location is a branch finder. This one is real — a fixed store list, haversine distances, a ranked result. Coarsen the origin the way accuracyMode: "approximate" does and watch whether the top result actually changes. Most of the time it does not, and that is the whole argument.

Find the nearest branch

Coarsening snaps the origin to a grid, which is roughly what a coarse location does: it names a cell, not a point. The true ranking is always computed from the exact origin, so the table can tell you honestly whether the coarse answer would have been wrong.

Branches ranked from the coarsened origin
#BranchDistance from coarse originTrue distanceSame answer?

code path

// A branch finder needs to rank a list, not to place a pin. Ranking is
// stable under a coarse origin whenever the branches are further apart
// than the accuracy radius — which, for a national retailer, they are.
const position = await new Promise((resolve, reject) =>
  navigator.geolocation.getCurrentPosition(resolve, reject, {
    accuracyMode: "approximate",
    maximumAge: 600000,
  })
);
const ranked = stores
  .map((store) => ({ store, km: haversineKm(position.coords, store) }))
  .sort((a, b) => a.km - b.km);

see also