Build a Chain Store Locator
A Go CLI that finds all locations of a brand near you, calculates driving distances, and prints them sorted by travel time.
Type a brand name and your location, get back every matching store sorted by how long it takes to drive there. This is a Go CLI — no web server, no frontend.
What you’ll use
Section titled “What you’ll use”- Geocoding to turn your location into coordinates
- PlazaQL to find all locations of a brand by OSM tags
- Distance matrix to rank results by driving time
Key code
Section titled “Key code”The interesting part is the PlazaQL query. OpenStreetMap has detailed brand tagging — a Whole Foods isn’t just shop=supermarket, it has brand=Whole Foods Market and a Wikidata link. We use a regex match to catch all variants:
query := fmt.Sprintf( `$$ = search(brand: ~"%s").around(distance: 25000, geometry: point(%f, %f));`, brand, lat, lng,)The ~ operator does regex matching — so “whole foods”, “Whole Foods Market”, and “WHOLE FOODS” all match. We search all element types (nodes and ways) by omitting the type argument, because stores can be mapped as either a point or a building outline. distance: 25000 restricts results to within 25km.
Once we have the store locations, we feed them into the distance matrix API — one origin (you), many destinations (the stores):
matReq := MatrixRequest{ Origins: [][]float64{{originLat, originLng}}, Destinations: destinations, Profile: "car", Annotations: []string{"duration", "distance"},}Then attach the results and sort:
for i := range stores { stores[i].DriveTime = matrix.Durations[0][i] stores[i].Distance = matrix.Distances[0][i]}
sort.Slice(stores, func(i, j int) bool { return stores[i].DriveTime < stores[j].DriveTime})How it works
Section titled “How it works”- Geocode your location to get lat/lng coordinates.
- PlazaQL query searches OSM’s
brandtag within a 25km radius. This catches every location that community mappers have tagged, which for major chains is comprehensive. The Name Suggestion Index is the canonical source for brand tags. - Distance matrix calculates real driving times from you to every store in one API call. This is much better than straight-line distance — a store 2km away across a river might be a 15-minute drive.
- Sort by drive time and print a table.
Full source
Section titled “Full source”The complete working app is at github.com/plazafyi/example-apps/store-locator. It’s a Go CLI with a thin Plaza API client wrapper.
git clone https://github.com/plazafyi/example-appscd example-apps/store-locatorexport PLAZA_API_KEY=your-key-herego run . "Whole Foods" "Union Square, NYC"Variations to try
Section titled “Variations to try”Filter by what’s open. OSM has opening_hours tags. Parse them to show only stores currently open.
Add the nearest competitor. Run a second PlazaQL query for a competing brand and show both in the output. “Nearest Whole Foods: 3 min. Nearest Trader Joe’s: 7 min.”
Find specific services. Many stores have extra tags like organic=yes, bulk_purchase=yes, or wheelchair=yes. Add these to the PlazaQL filter.
Export to JSON. Add a --json flag that prints the results as structured JSON for piping into other tools.