Skip choice for unique postcode matches

This commit is contained in:
Edward Betts 2026-08-15 12:09:24 +01:00
parent 71e1b57164
commit 7da704d837
4 changed files with 36 additions and 1 deletions

View file

@ -51,6 +51,11 @@ function parseCoordinates(value) {
return {lat, lon};
}
/** Return whether text has the shape of a complete UK postcode. */
function isUkPostcode(value) {
return /^(?:GIR\s*0AA|[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2})$/i.test(value.trim());
}
/** Put the current search in the address bar without reloading the page. */
function setSearchUrl(params, replace = false) {
const query = params.toString();
@ -305,6 +310,10 @@ function renderStops(data, fitMap = true, sortOrigin = null, preserveSelection =
/** Show UK-only Nominatim matches and wait for the user to choose one. */
function renderGeocodeChoices(data) {
if (data.locations.length === 1 && isUkPostcode(data.query)) {
chooseLocation(data.locations[0]);
return;
}
selectedStop = null;
markers.clearLayers();
if (searchMarker) { searchMarker.remove(); searchMarker = null; }

View file

@ -40,7 +40,7 @@
<tbody>
<tr>
<td><code>q</code></td>
<td>A postcode, street, place name, or exact ATCO code. Place searches show up to 20 UK-only matches to choose from.</td>
<td>A postcode, street, place name, or exact ATCO code. Place searches show up to 20 UK-only matches to choose from; a postcode with one match opens directly.</td>
<td><a href="{{ url_for('index', q='Bristol Temple Meads') }}"><code>{{ url_for('index') }}?q=Bristol+Temple+Meads</code></a></td>
</tr>
<tr>