Reinos.nl internet media examples

Open now: JSON endpoint

Maps Locator 4.0.1 Code only

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.

  1. Install Maps Locator and Maps.
  2. Create the fields, with these short names:
    Short nameTypeNotes
    store_locationMapsSet 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 HoursThe week and the exceptions (holidays).
  3. Create the channel stores (Stores) and assign the fields.
  4. 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).
  5. Put the code in a template.
  6. 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.