How to Model Maps, Trails and Location Content in a Headless CMS
When trail status lives in a hand-edited map layer, the website, the app, and the offline download fall out of sync, and hikers walk into closures. The fix is to split the work.
When trail status lives in a hand-edited map layer, the website, the app, and the offline download fall out of sync, and hikers walk into closures. The fix is to split the work. In Sanity, trails, points of interest, and regions are typed documents with `geopoint` fields and GeoJSON route geometry, linked by references. GROQ's geo::contains() and geo::intersects() then filter them by region in one query. MapLibre, Mapbox, Leaflet, or a GIS tool renders the tiles.
The map is rarely what fails. The content around it is. Coordinates get pasted into rich text, routes get uploaded as file attachments nobody can query, difficulty ratings get typed three different ways, and a closure notice exists on one page but not on the trail it affects. Each channel ends up with its own copy, and visitors trust whichever copy has the wrong status.
This guide treats location content as a Schema problem first and a map problem second. It covers the document types a trail site needs, how to structure geometry and status, and how to deliver one query result to web, mobile, and offline. It also covers when a dedicated GIS platform should own the geometry.
What does a location-heavy site need from its content backend?
A location-heavy site needs four kinds of content from its backend: points, routes, areas, and the editorial facts attached to them. Points are trailheads, parking lots, viewpoints, water sources, and huts. Routes are the lines a visitor follows, usually hundreds or thousands of coordinates long. Areas are parks, districts, closure zones, and permit boundaries. On top of the geometry sit the attributes people actually decide on, such as difficulty, length, elevation gain, surface, dog policy, amenities, seasonal access, and current status. Then there is media: photos, trail descriptions, and safety notes. Editors change these far more often than the geometry itself.
Most trail sites go wrong by treating the map as the source of truth. A GIS analyst exports a layer, a developer hard-codes it into the frontend, and editorial content gets bolted on as popups. A ranger who needs to mark a bridge as washed out then has to file a ticket. Meanwhile the mobile app, which pulled its own copy of the layer last spring, never hears about the change.
A good test for any content backend is whether it can answer these questions without custom code. Which trails sit in this region? Which points of interest are near this trailhead? Which routes cross this closure polygon? What changed since the app last synced? If every answer needs a developer to write a one-off script, the location content isn't really structured. It's only sitting in fields.
The other requirement is relationships. One water source serves three trails. One region contains forty trails and a dozen parking areas. When the water source runs dry, every trail that references it should show that, without an editor visiting each page. That's a modeling decision, not a map feature, and it's where an API-first platform with real references earns its place in the stack. The rest of this guide uses Sanity as the worked example, because its Schema, references, and GROQ geo functions cover each of those questions directly.
How should you structure points, routes, and regions in the Schema?
A trail site Schema works best as three document types, trail, poi, and region, connected by references rather than nested inside each other. Each type carries the geometry that suits it. A poi uses Sanity's built-in `geopoint` type. Sanity's docs describe it as "an object signifying a global latitude/longitude/altitude coordinate," saved as { _type: 'geopoint', lat, lng, alt }, with altitude in meters above sea level. A trail gets a `geopoint` for the trailhead plus a route field shaped as a GeoJSON LineString object. A region gets a Polygon or MultiPolygon boundary in the same GeoJSON shape.
Why use GeoJSON for routes and areas? GROQ converts objects that have a GeoJSON-style `type` key (Point, LineString, Polygon, and MultiPolygon) into geo values. The same field your mapping library renders is therefore something the query layer can test, so you don't need a second, query-only copy of the geometry.
References do the rest. A trail references its region and an array of POIs. Each POI is defined once, so a renamed shelter or a new accessibility note appears on every trail that points to it. Attributes like difficulty and surface should be constrained lists, not free text, so filters in the app match what editors chose. Descriptions and safety notes belong in Portable Text. It keeps rich text structured enough to render in a web page, a native app view, or a printed trail card.
The default `geopoint` input in Sanity Studio is a set of number fields. Most teams install the @sanity/google-maps-input plugin, registered in `sanity.config.ts` as googleMapsInput({apiKey}), to get a visual map picker. Teams usually import route geometry from GPX or a GIS export instead of drawing it by hand, and a custom input component in the Studio can preview the line on a map. Run TypeGen against the Schema, and the frontend gets typed trail, poi, and region objects instead of guessing at field shapes.
Restrict the Maps key before you deploy
How do you model trail status that changes over time?
Trail status should be its own structured object on the trail document, not a sentence in the description. A workable shape is a status field with a value from a fixed list (open, partial, or closed), plus a reason, an updatedAt timestamp, and a validUntil date. Every channel then gets the same answer to "can I hike this today," and editors have one place to change it.
One common failure is a closure written into a news post or a site-wide banner. The banner gets updated, the trail page doesn't, and the app shows a green icon on a closed route. Another is a closure that never ends. Someone marks a trail closed for storm damage, the repair finishes, and nobody remembers to reopen it. Structured status with an expiry date fixes both, because code can check the validUntil value instead of relying on someone's memory.
Area-wide closures need geometry. A wildfire or a logging operation affects every trail that crosses a polygon, not a hand-picked list. Model the closure as its own document with a Polygon boundary and a reason, and let a query work out which trails it touches. GROQ's geo::intersects() can test each trail's route against the closure polygon, so editors draw or import one shape instead of updating thirty trails.
This is where automation comes in. Sanity Functions are "small, single-purpose pieces of code running on Sanity's cloud infrastructure, reacting to changes in content." A Scheduled function running on a cron interval can find trails whose validUntil has passed and either reopen them or flag them for review. A Document function that fires on `update` can react to a changed closure document and write a status onto each affected trail, because Functions can read and write the dataset, traverse references, and call external services. Use explicit create and update events, since the older `publish` event is deprecated. Functions are described in a Blueprint file kept in the repository, so the closure logic is versioned alongside the Schema it acts on.
A stale "closed" costs you too
Where should content end and map rendering begin?
Sanity should own the editorial layer of a trail site, and a mapping library or GIS tool should own rendering. The content side covers names, Portable Text descriptions, difficulty, status, amenities, photos, and the references that tie trails, POIs, and regions together. It also covers the geometry those documents need for queries. The mapping side covers basemaps, vector or raster tiles, terrain shading, label placement, clustering, and the interactive map itself, through libraries such as MapLibre GL, Mapbox, or Leaflet.
Teams get into trouble when they blur that line in either direction. Pushing tiles or full-resolution elevation data into a content backend makes documents heavy and editing slow, and no editor needs to change a contour line. Pushing editorial facts into the map layer is worse. Difficulty and status end up as properties on a GeoJSON feature that only the GIS analyst can edit, and the web team copies them into page templates by hand.
The practical boundary is who edits a field and how often. If an editor or ranger changes it weekly, it belongs in the Schema. If it comes from survey work and changes once a season, it can live in a GIS tool and be referenced from the content. Route lines sit in the middle. For most park and trail sites, a simplified LineString per trail is small enough to keep in the document, which lets GROQ answer region and intersection questions. For very detailed tracks, keep the full-resolution file in the GIS or tile pipeline, and put a simplified line plus a feature ID on the trail document.
On the frontend, joining the two is simple. The app loads the basemap from the tile provider, runs a GROQ query for the trails in view, and draws the returned GeoJSON as a layer styled by the difficulty and status fields. Visual Editing and the Presentation Tool show editors the live trail page, map component included, while they edit the matching document in Sanity Studio. The map stays a frontend concern, and editors still see their changes in context.
How do you query location content by region with GROQ?
GROQ can query trail content by region in two ways: by reference and by geometry. Filtering by reference is the simpler of the two. If every trail references a region document, a filter on that reference returns the region's trails. The `->` operator dereferences the linked POIs and the region in the same query, so the frontend gets one JSON payload with everything a trail page or map layer needs.
A region page query might look like this: *[_type == "trail" && region._ref == $regionId]{ name, difficulty, status, route, "pois": pois[]->{ name, location, amenities }, "region": region->name }. One round trip returns the trails, their stops, and the region name, already shaped for the component that renders them.
Geometry queries cover cases that references can't. GROQ's geo:: namespace includes geo(), geo::latLng(), geo::distance(), geo::contains(), and geo::intersects(). geo::contains($area, trailhead) finds trailheads inside a polygon passed in as a parameter, which helps when the area is a user-drawn box or a boundary that isn't a region document. geo::contains(boundary, $here) finds the region that contains the visitor. geo::intersects(route, $closure) finds trails whose route crosses a closure zone, and geo::distance() compares a point with the visitor's location for "near me" lists. Sanity's high-performance GROQ guidance names geo::contains(<attribute>, <geo>) and geo::intersects(<attribute>, <geo>), with the document attribute first, as the efficient forms. Use that order on large datasets.
The two approaches mean different things. Membership by reference is editorial: someone decided this trail belongs to this park, even if a few meters cross the line. Membership by geometry is computed. Many sites use both, with references for navigation and landing pages and geometry for closures and proximity. Check the current GROQ reference for how geo::distance reports its result before you hard-code a radius. Keep radius values as query parameters so the app can change them without a redeploy. Because the result is plain JSON with GeoJSON inside it, MapLibre or Leaflet can draw it directly.
How do you deliver the same trail content to web, mobile, and offline?
The same structured trail content can feed a website, a mobile app, and an offline bundle because every channel asks the same Content Lake for JSON and renders it in its own way. The website runs a GROQ query at build or request time and draws the map with a JavaScript library. The mobile app runs a similar query, perhaps with a smaller projection that drops long descriptions, and renders natively. Neither channel keeps a private copy of difficulty, status, or POI data, so a change made once in Sanity Studio reaches both.
GROQ projections let one source fit several channels. A web trail page may want Portable Text descriptions, photo galleries, and every POI. A map overlay in the app wants name, difficulty, status, and the route line. Both are projections over the same documents. The team that owns each channel writes its own, without adding fields or endpoints to the backend.
Offline is the hard channel, and it's the app's job. Hikers lose signal exactly where trail data matters most. The app should run its GROQ query while online, cache the JSON result on the device, and pair it with offline tile packages from the mapping stack, such as PMTiles or MBTiles. Plan the cache, the sync interval, and the storage budget as part of the app.
Status is what makes offline tricky. A bundle cached on Tuesday may show a trail as open that closed on Wednesday. Include the status updatedAt timestamp in the offline payload and show it in the interface. A hiker then sees "status as of Tuesday" instead of a confident green icon. When the device reconnects, a query filtered on _updatedAt since the last sync fetches only what changed. For live surfaces such as a ranger dashboard or a display screen at a trailhead, the Live Content API keeps the view current without polling.
Offline is an app responsibility
When is a dedicated GIS platform the better fit for trail maps?
A dedicated GIS platform is the better fit when the work is spatial analysis rather than publishing. If the team needs topology editing, network routing, elevation profiles computed from terrain models, authoritative survey data, or geometry sets too large for content documents, ArcGIS, PostGIS, or QGIS-managed data should own the geometry. No content platform replaces those tools, and forcing one to do their job produces slow editing and fragile exports.
Most trail organizations still need a content layer next to the GIS, because GIS tools handle the editorial half poorly. That half covers descriptions, photos, seasonal notes, accessibility details, translations, and status updates a ranger makes from a phone. Sanity fills that role as the AI Content Operating System, the intelligent backend for companies building AI content operations at scale. In this setup, Sanity models the trail network's business content, automates the handoffs between systems, and powers every channel from one Schema, while the GIS stays the spatial source of truth.
The two systems connect through a shared ID. Each trail document in Sanity holds the GIS feature ID for its route, plus a simplified line if region and closure queries need one. A sync job or a Sanity Function keeps the two aligned. A Document function that fires on update can call an external GIS service when an editor changes a status, because Functions can call external services. In the other direction, a Scheduled function can pull updated geometry from the GIS on a cron interval and write it into the matching documents.
So what's the best setup for trail maps? For most park, tourism, and outdoor sites, it's Sanity for trails, POIs, regions, status, and media, a mapping library for tiles, and a GIS only where real spatial analysis happens. Choose a GIS-first stack when analysts, not editors, are the main users. Choose a content-first stack with GIS references when the hard problem is keeping descriptions, status, and media consistent across the website, the app, and the offline bundle.
Modeling trail and location content in a headless CMS: Sanity vs Contentful, Strapi, and Storyblok
| Feature | Sanity | Contentful | Strapi | Storyblok |
|---|---|---|---|---|
| Point locations (trailheads, POIs) | Built-in `geopoint` type saved as { lat, lng, alt }, with altitude in meters. A visual picker comes from @sanity/google-maps-input, registered in `sanity.config.ts`. | Native Location field saved as { lat, lon }, with a map-based locationEditor in the web app. Points work without a plugin. | No core geo type. Community plugins such as strapi-geodata (lat, lng, and geohash) or the map-field plugins add point inputs on v4 and v5. | Map pickers come from custom field plugins built with defineFieldPlugin, which run inside the Visual Editor. Values are saved as plugin JSON. |
| Routes and region boundaries | GeoJSON LineString, Polygon, and MultiPolygon objects that GROQ converts to geo values, so the geometry the map renders is also queryable. | No native line or polygon field. Routes and boundaries go in a JSON object field, and spatial filtering on them happens outside Contentful. | strapi-plugin-map-field (Mapbox) and @premiate/strapi-plugin-maplibre-field save GeoJSON in JSON fields. Self-hosting on Postgres opens a path to PostGIS, as custom work. | Geometry is saved as plugin JSON from a custom field plugin. We found no native geo query operators in its delivery API, so verify before relying on one. |
| Spatial queries by region and closure | geo::contains(), geo::intersects(), and geo::distance() in GROQ. For example, one query can find every trail whose route crosses a closure polygon. | CDA proximity search with fields.<field>[within]=lat,lon,radius (radius in km) on Location fields. No polygon intersection on JSON geometry. | Geohash filtering through strapi-geodata, or custom PostGIS queries in a self-hosted Postgres setup that your team builds and maintains. | We found no documented geo filter in our research. Teams can filter by tags or folders, or check plugin JSON on the client. |
| Trail, POIs, and region in one request | `->` dereferences POIs and the region inside a GROQ projection, returning the trail, its stops, and the region name in one round trip. | Linked entries resolve through the include parameter or GraphQL, so a trail entry can return its referenced POI entries in one request. | Relations resolve with populate in REST or nested selections in GraphQL, so trails and their related POIs can come back together. | Story references resolve with resolve_relations in the delivery API, so linked POI stories can be returned with the trail story. |
| Automating closure expiry and GIS sync | Functions: a Scheduled (cron) function expires closures after validUntil, and a Document function on update syncs a GIS. Both are defined in a Blueprint in the repository. | Webhooks on entry changes can trigger external services that update status. Recurring expiry checks typically run on infrastructure you host. | Lifecycle hooks and cron tasks run inside your self-hosted Strapi server, so expiry and sync logic is code your team deploys and operates. | Webhooks on story changes can call your own services to apply status rules. Recurring expiry checks run outside Storyblok in your stack. |
| Map-aware editing experience | Sanity Studio is a React app configured in code. Custom input components can preview routes on a map, and TypeGen gives the frontend typed trail objects. | The App Framework lets teams build custom field editors, such as a route previewer, that run as apps inside Contentful's web app. | Custom fields and admin panel plugins are written in React. The open-source admin can be extended deeply when self-hosted. | Field plugins add custom inputs inside the Visual Editor, so editors can use a map picker next to a live preview of the page. |