Store locator Pro
A store finder as retailers and Google Maps show one. Search by area, street or postcode; filter by Open now and services; the list is nearest first and stays in sync with the map, where stores cluster while they crowd and slide apart as you zoom. Pick a store for its hours (today in bold), address and walk, services, a call button, directions in the phone's maps app, and "make this my store". On desktops the list sits beside the map; on phones it lives in a sheet over the map that rests at a peek, half or full.
Built from MapView (MapClusters, MapUserLocation, MapSheet) and free components.
import { StoreLocatorScreen } from '@patine-ui/pro';
<StoreLocatorScreen />;
<View style={{ width: '100%', height: 680 }}> <StoreLocatorScreen /> </View>
Open now, in words
openStatus(store, now) says what a maps app says: "Open · closes 8 PM", "Closes soon · 8 PM" within the hour (in amber), "Closed · opens 9 AM tomorrow", "Closed · opens Monday 9 AM", "Open 24 hours". Hours are per weekday in minutes after midnight, Sunday first like Date.getDay(), and null for a closed day. The screen re-checks every minute; pass now to pin it (for tests and screenshots).
const store = {
hours: [null, [540, 1200], [540, 1200], [540, 1200], [540, 1260], [540, 1260], [600, 1080]],
};
openStatus(store, new Date()); // { open: true, closingSoon: false, label: 'Open · closes 8 PM' }
Make it yours
| Prop | Type | Default |
|---|---|---|
stores | Store[]: id, name, area, address, postcode, coordinate, phone, hours, services, rating, reviews | The Halden demo, 19 London stores |
location | { lat, lng }: the person's place, from your location library | By the Strand |
now | Date | Now, kept current |
onDirections | (store) => void | Opens Apple Maps on iOS, Google Maps elsewhere (directionsUrl) |
onCall | (store) => void | Dials the store |
onChooseStore | (store) => void: "Make this my store" | |
title | string | 'Find a store' |
findStores(stores, from, { query, openNow, services }, now) does the search, filters and distance sort, so a server-side search can return the same shape. Services are listed in STORE_SERVICES; change their labels and icons there.
The map opens on OpenStreetMap's tiles, which suit development. For production, pass a provider's URL with your key to MapView (see Tiles).
Built with
The free components, from patine-ui:
Button · Heading, Text · SearchField · Separator
And from Patine Pro:
- App shell and layout PRO
- Map PRO
- Patine Icons, the Pro set PRO
Files
store-locator/
├── components/
│ ├── StoreDetail.tsx
│ ├── StoreParts.tsx
│ ├── StorePin.tsx
│ └── StoreRow.tsx
├── hooks/
│ └── useStoreLocator.ts
├── index.ts
├── store-locator.constants.ts
├── store-locator.types.ts
├── store-locator.utils.ts
└── StoreLocatorScreen.tsx
A look at the code
Directions in the phone’s own maps app, and walking time, from store-locator.utils.ts:
/** A link that opens directions to the store in the phone's maps app: Apple Maps on iOS, Google Maps elsewhere. */
export const directionsUrl = (store: Pick<Store, 'coordinate' | 'name'>, os: string) => {
const { lat, lng } = store.coordinate;
return os === 'ios'
? `https://maps.apple.com/?daddr=${lat},${lng}&q=${encodeURIComponent(store.name)}`
: `https://www.google.com/maps/dir/?api=1&destination=${lat},${lng}`;
};
/** About how long a walk takes, at 5 km/h: "6 min walk", "1 h 10 min walk". */
export const walkTime = (meters: number) => {
const min = Math.max(1, Math.round(meters / 83));
return min < 60 ? `${min} min walk` : `${Math.floor(min / 60)} h ${min % 60} min walk`;
};
Accessibility
- Every store row and pin is a button named with the store, distance and whether it's open; the selected one is marked selected.
- Filters are checkboxes; the hours row is an expandable button.
- The sheet's handle steps through its heights on press or Enter, so it never needs a drag.
- Opening status is in words as well as colour.