Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions server/utils/places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@ export async function geocodeAddress(address: string, apiKey: string): Promise<G
}

// Non-commercial place types we never want cluttering discovery results
// (transit stops, worship places, government/civic buildings, parks, schools).
// (transit stops, worship places, government/civic buildings, parks, schools,
// residential buildings).
// See https://developers.google.com/maps/documentation/places/web-service/place-types
// Note: not every plausible-looking type string is actually valid as an
// excludedTypes value — Google rejects unknown ones with a 400 for the
// whole request (confirmed: 'toll_booth' and 'point_of_interest' are NOT
// accepted here, even though they're valid primaryType values on a place).
const DEFAULT_EXCLUDED_TYPES = [
'bus_station', 'train_station', 'subway_station', 'light_rail_station',
'transit_station', 'airport', 'taxi_stand', 'ferry_terminal', 'heliport',
'bus_station', 'bus_stop', 'train_station', 'subway_station', 'light_rail_station',
'transit_station', 'transit_depot', 'airport', 'taxi_stand', 'ferry_terminal', 'heliport',
'park', 'stadium',
'mosque', 'church', 'hindu_temple', 'synagogue', 'cemetery',
'parking', 'rest_stop',
'city_hall', 'government_office', 'local_government_office', 'courthouse', 'embassy',
'fire_station', 'police', 'post_office',
'school', 'primary_school', 'secondary_school', 'university',
'gas_station', 'atm', 'butcher_shop',
// Residential buildings: Google returns these next to street-level shops,
// but a block of flats has no owner to pitch to.
'apartment_building', 'apartment_complex', 'condominium_complex', 'housing_complex',
]

// Types Google returns as a place's primaryType but refuses as an
Expand Down Expand Up @@ -113,7 +117,12 @@ export async function nearbySearch(
body,
})

const filtered = (res.places ?? []).filter(p => !POST_FILTER_EXCLUDED_TYPES.includes(p.primaryType ?? ''))
// A missing primaryType means Google has no supported category for the place
// at all. In practice these are half-registered map entries ("kırmızı el
// arabası", a person's name on a doorway) — never something to sell to.
const filtered = (res.places ?? [])
.filter(p => p.primaryType)
.filter(p => !POST_FILTER_EXCLUDED_TYPES.includes(p.primaryType!))

return filtered.map((p) => {
const reviews: ReviewSnippet[] = (p.reviews ?? [])
Expand Down