Skip to content
GuidesBlogPlaygroundDashboard

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.

  • 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

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
})
  1. Geocode your location to get lat/lng coordinates.
  2. PlazaQL query searches OSM’s brand tag 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.
  3. 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.
  4. Sort by drive time and print a table.

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.

Terminal window
git clone https://github.com/plazafyi/example-apps
cd example-apps/store-locator
export PLAZA_API_KEY=your-key-here
go run . "Whole Foods" "Union Square, NYC"

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.