A request with open_now=1 gets only the stores that are open now. Every location has open_now, closes_at, opens_at, opens_day and hours_today (null for a store without opening hours):
Template
<script>
const searchUrl = '{exp:reinos_maps_locator:search_url channel="stores" limit="20"}';
async function findStores(location, openNow) {
const params = new URLSearchParams({ location, radius: 25 });
if (openNow) {
params.set('open_now', '1');
}
const data = await (await fetch(`${searchUrl}&${params}`)).json();
return data.locations.map(store => ({
title: store.title,
status: store.open_now === null ? ''
: store.open_now ? `Open until ${store.closes_at}`
: store.opens_at ? `Closed, opens ${store.opens_day} at ${store.opens_at}`
: 'Closed',
}));
}
findStores('utrecht', true).then(stores => console.log(stores));
</script>Build it in your own site
What this example needs in ExpressionEngine, step by step.
- Install Maps Locator and Maps.
- Create the fields, with these short names:
Short name Type Notes store_locationMaps Set the field setting Mode to Single location: one marker per store, placed with the search field. Maps Locator indexes that marker, so this one field is the location for the map and the search. store_hoursMaps Locator Opening Hours The week and the exceptions (holidays). - Create the channel
stores(Stores) and assign the fields. - In the settings of Maps Locator, turn on Reverse geocoding: a marker of a Maps field is saved as a coordinate, the reverse geocoding looks up its address and city (the city pages and a search on a city need them).
- Put the code in a template.
- Add a few stores (the demo site has 34 bike stores in the Netherlands).
This example comes from the Maps Locator docs: the preview runs exactly the code above.