From 361a826e4fd495cfec112da4f7721d6ecfac851b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Tue, 24 Feb 2026 09:58:12 +0400 Subject: [PATCH] Improve nearby search * Use regular expression queries for place types * Add more place types * Add relations * Only return results with a name --- app/components/place-details.gjs | 4 ++-- app/services/osm.js | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/components/place-details.gjs b/app/components/place-details.gjs index 7d9e324..ac95cb9 100644 --- a/app/components/place-details.gjs +++ b/app/components/place-details.gjs @@ -83,7 +83,7 @@ export default class PlaceDetails extends Component { } parts.push(city); } - + // State + Country (if not already covered) const state = get('addr:state', 'state'); const country = get('addr:country', 'country'); @@ -151,7 +151,7 @@ export default class PlaceDetails extends Component { if (!id) return null; return `https://www.google.com/maps/search/?api=1&query=${this.name}&query=${this.place.lat},${this.place.lon}`; } - + get showDescription() { // If it's a Photon result, the description IS the address. // Since we are showing the address in the meta section (bottom), diff --git a/app/services/osm.js b/app/services/osm.js index e03d29a..9028cc7 100644 --- a/app/services/osm.js +++ b/app/services/osm.js @@ -24,14 +24,31 @@ export default class OsmService extends Service { this.controller = new AbortController(); const signal = this.controller.signal; + const typeKeys = [ + 'amenity', + 'amenity', + 'shop', + 'tourism', + 'historic', + 'leisure', + 'office', + 'craft', + 'building', + 'landuse', + 'public_transport', + 'aeroway' + ] + const typeKeysQuery = [`~"^(${typeKeys.join("|")})$"~".*"`]; + const query = ` [out:json][timeout:25]; ( - nw["amenity"](around:${radius},${lat},${lon}); - nw["shop"](around:${radius},${lat},${lon}); - nw["tourism"](around:${radius},${lat},${lon}); - nw["leisure"](around:${radius},${lat},${lon}); - nw["historic"](around:${radius},${lat},${lon}); + node(around:${radius},${lat},${lon}) + [${typeKeysQuery}][name~"."]; + way(around:${radius},${lat},${lon}) + [${typeKeysQuery}][name~"."]; + relation(around:${radius},${lat},${lon}) + [${typeKeysQuery}][name~"."]; ); out center; `.trim();