Geocoder
more-shadcn-noair/geocoderFreeComponent
A geocoder component that provides search and autocomplete functionality for location-based queries. It can be used to find addresses, places, or points of interest based on user input.
Live preview
live · rendered by the registry
Rendered by more-shadcn-noair on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://more-shadcn.noair.fun/r/geocoder.jsonSource
1<script lang="ts">2 import { Input } from '$lib/components/ui/input';3 import { cn } from '$UTILS$';4 import { Check, Loader, MapPin, X } from '@lucide/svelte';5 import { fly } from 'svelte/transition';6 import type { Snippet } from 'svelte';7 import type { GeoLocation } from '.';8 import Highlight from './geocoder-highlight.svelte';9 import { formatAddress, type AddressConvention } from './format';1011 let {12 value = $bindable(''),13 selected = $bindable<GeoLocation | null>(null),14 loading = false,15 placeholder = 'Search for a location...',16 labelKey,17 format = 'short',18 convention = 'auto',19 showCountry = true,20 language,21 class: className,22 onSelect,23 locationSnippet,24 emptySnippet,25 ...rest26 }: {27 value: string;28 selected?: GeoLocation | null;29 loading?: boolean;30 placeholder?: string;31 labelKey?: keyof GeoLocation;32 /**33 * `short` builds a compact address from the structured fields, `full` uses34 * Nominatim's raw `display_name`, or pass a function for total control.35 */36 format?: 'short' | 'full' | ((location: GeoLocation) => string);37 /** Address ordering. `auto` follows the country of each result. */38 convention?: AddressConvention | 'auto';39 showCountry?: boolean;40 /** Sent as `accept-language`, so results come back localised. */41 language?: string;42 class?: string;43 onSelect?: (loc: GeoLocation) => void;44 locationSnippet?: Snippet<[GeoLocation, boolean]>;45 emptySnippet?: Snippet;46 [key: string]: any;47 } = $props();4849 /** The single source of truth for a result's label. */50 function label(loc: GeoLocation) {51 if (typeof format === 'function') return format(loc);52 if (format === 'full') return loc.display_name;53 return formatAddress(loc, { convention, showCountry });54 }5556 let isOpen = $state(false);57 let activeIndex = $state(-1);5859 let inputContainerRef = $state<HTMLDivElement | null>(null);60 let listRef = $state<HTMLDivElement | null>(null);6162 let options: GeoLocation[] = $state([]);6364 function open() {65 isOpen = true;66 activeIndex = -1;67 }6869 function close() {70 isOpen = false;71 activeIndex = -1;72 }7374 function handleInput(e: Event) {75 value = (e.target as HTMLInputElement).value;76 if (value.length > 0) open();77 else close();78 }7980 function handleSelect(loc: GeoLocation) {81 selected = loc;82 value = labelKey ? String(loc[labelKey]) : label(loc);8384 if (onSelect) onSelect(loc);85 close();86 }8788 function handleKeydown(e: KeyboardEvent) {89 if (!isOpen) {90// … truncated
What it pulls in
Other registry items
More from more-shadcn-noair
All 43 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audioaudio | more-shadcn-noair | Components | Free | no deps | |
| Audio Waveaudio-wave | more-shadcn-noair | Components | Free | no deps | |
| Autocompleteautocomplete | more-shadcn-noair | Components | Free | no deps | |
| Bannerbanner | more-shadcn-noair | Components | Free | no deps | |
| Big Calendarbig-calendar | more-shadcn-noair | Components | Free | no deps | |
| Bottom Navigationbottom-nav | more-shadcn-noair | Components | Free | no deps | |
| Canvascanvas | more-shadcn-noair | Components | Free | no deps | |
| Chipchip | more-shadcn-noair | Components | Free | no deps |
