Use case
Building a store locator
A store locator turns what a visitor types into a position and ranks your locations by how long they take to reach. With oslew that takes two requests: a geocode of the visitor’s text, which reports when the text names several places so you can ask instead of guessing, and one travel-time matrix from the visitor to your nearest stores, which orders them by driving or walking time rather than by straight-line distance. A nearby search can then list what is around the store they choose.
Last reviewed
Most store locators sort by distance as the crow flies, because it is easy and needs no routing. It is also often wrong in exactly the places where it matters: a river with few bridges, a ring road without a junction, a historic centre of one-way streets. The store nearest on the map can be the one furthest away in minutes. The workflow below orders stores by travel time instead, and costs two requests per search.
Step 1: geocode your stores once
Your store table is the fixed half of every search, so locate it once, when a store opens or moves, and keep the coordinates. Geocoding the whole table on every visitor search spends rate on answers that never change. Check each store’s result as you would any address you intend to rely on: an address point or an interpolated position, not a street or a town centre, and no tie. A store’s position is worth getting right once; a visitor’s position only needs to be good enough to rank a handful of stores minutes apart.
Step 2: locate the visitor, and ask when the text is ambiguous
Send what the visitor typed to the geocoding API. The field to read first is tied_at_top. When it is above one, the text names several places equally well and the first result is one of them chosen by prominence, not the one the visitor meant. Offer the tied candidates, with their locality and region, and let the visitor pick. When the candidates look identical — the same chain’s branch name in the same district — a list does not help; ask for a street, a postcode or a landmark instead.
An untied answer can be used as it is, and its precision matters less here than for a delivery: a street or a neighbourhood’s centre is a fine origin when the output is a ranking of stores. Two further choices depend on your catchment. If the locator serves one city, passing the city’s centre as near keeps a street name that also exists elsewhere from tying with those places; near is a hard filter to a cell of about 10 km, so for a wider area put the city or region after a comma as context instead. And if the visitor types only a postcode, the postcode lookup answers with the centre of that code’s addresses, which is a sensible origin.
If the browser already knows where the visitor is, from the device’s location, skip this step and use that position directly.
Step 3: one matrix, not many routes
Next, shortlist your stores by straight-line distance, down to one fewer than the plan’s matrix side, because the visitor takes the first place. Then send the visitor followed by the shortlisted stores to the distance matrix API in one request. The answer is a square table of travel times; the first row is the time from the visitor to each store, which is the ranking you want. If the question is instead which store can deliver to the visitor soonest, read the first column: the matrix is not symmetric, because one-way streets are not.
A matrix is one request and one token from the routing bucket, whatever its size, so ask for the largest your plan allows rather than several small ones. The plan’s side is a hard cap: 100 × 100 on Routing, 200 × 200 on Platform, 500 × 500 on Scale. A request over it is refused, not quietly trimmed, and retrying will not change that. Choose the profile to match how people arrive: driving for an out-of-town retail park, walking for a city-centre shop. Each profile is its own network, not just a different speed.
Step 4: rank, and be honest about gaps
Sort the shortlist by its time. Some cells can be empty: a point that did not snap to a road within reach, which empties that point’s whole row and column, or a pair with no route between them in that direction. Never treat an empty cell as zero, or “nearest” becomes “the one we could not reach”. Rank the timed stores first and the untimed ones after them by straight-line distance, and show that figure as a distance, not as a time estimated from a guessed speed. A visitor told a distance can judge it; one told a made-up number of minutes cannot.
Optional: what is near the chosen store
Once a visitor picks a store, nearby places search can list what is around it — parking, a pharmacy, somewhere to eat — filtered by category. Its open_at filter only knows hours an attributes feed carries and drops every place without them, so use it only where hours are known. Nearby search is part of the Search product, which the Routing plan does not include; on that plan, leave the step out.
Times are free-flow
Matrix times are computed on the road network at free-flow speeds: they describe a clear road, not the evening peak. Congestion enters the times only where an operator applies a traffic feed, which is the Enterprise operator product; the difference, and when it matters for a ranking, is covered in free-flow vs traffic-aware routing. For ranking a handful of nearby stores, free-flow times already capture what a straight line misses — the river, the ring road, the one-way system.
Routing answers are derived from OpenStreetMap data and carry ODbL-1.0. Showing a visitor a ranked list is ordinary use; publishing a database of travel times built from those answers would carry share-alike.
Which plan
A locator needs the Address product for geocoding and the Routing product for the matrix. The Routing plan is $299 a month, with 20 requests a second sustained, burst 100 of address requests and 5 requests a second sustained, burst 25 of routing. Platform, at $699 a month, raises routing to 20 requests a second sustained, burst 100, doubles the matrix side and adds the Search product for the nearby step. Each search costs one geocode and one matrix, however many stores the matrix compares, and none of it is billed per request; the pricing page has the full table.
Bottom line
Geocode stores once, geocode visitors per search and ask when the answer is tied, then let one matrix request order your nearest stores by real travel time. Show untimed stores last, as distances, and keep the key on your server — a locator is usually a public web page, and its matrix call belongs behind your own route.
Where this workflow falls short
- Matrix times run between the road junctions nearest each point, so they can differ by seconds from a full route between the same two places, and the walk from a car park to the door is not in them.
- A store with no time — its point did not snap to the road network, or no route connects the pair — has to be ranked by straight-line distance and labelled as a distance, never given an estimated time.
- Travel times are computed at free-flow speeds. Rush-hour delays are reflected only where an operator applies a traffic feed, which is part of an Enterprise agreement.
- Opening hours for the nearby step exist only where an attributes feed carries them, and a place without hours never appears in an open-now search.
Questions
How do I build a store locator with an API?
Geocode each store once and keep its coordinates. For each visitor, geocode what they type, asking them to choose when the answer is tied. Shortlist your stores by straight-line distance, send the visitor and the shortlist as one travel-time matrix, and sort the stores by the time from the visitor to each.
Why rank stores by travel time instead of distance?
Because a straight line ignores what is between two points. A river with few bridges, a motorway with no junction nearby or a one-way system can make the store closest on the map the slowest to reach. A matrix of travel times on the road network orders the stores by what the visitor will actually experience.
How many stores can one matrix request compare?
As many as the plan’s matrix side allows, less one for the visitor: 100 × 100 on Routing, 200 × 200 on Platform and 500 × 500 on Scale. A larger matrix is refused rather than trimmed, so shortlist by straight-line distance first; with stores reasonably dense, the one nearest by road is among them, and if yours are sparse enough to doubt it, you have few enough to send them all.
What should a store locator do when the place typed is ambiguous?
Ask. When several candidates tie for first place, show them with their locality and region and let the visitor choose. When the candidates cannot be told apart by anything you can show — the same name in the same district — ask for a street, a postcode or a landmark instead of a list.