Understanding regions/geopolygon for geopoint queries in Sanity

3 replies
Last updated: Nov 30, 2025
After reading the docs I am not sure I fully understand regions for geopoint queries. The placeholder name is geopolygon, so are we just doing four points that are themselves sets of lat/long?
AI Update

Yes, you're on the right track! The geopolygon placeholder name refers to a polygon defined by multiple coordinate points (sets of lat/long), but it's not limited to just four points—it can be any number of points that define a closed shape.

How geopoint regions work

The geo functions in Sanity use GeoJSON format under the hood. When you see geopolygon in the docs, it's referring to a geographic polygon that can be:

  1. Created from a GeoJSON object with a type property set to "Polygon" (or other geometry types like "MultiPolygon")
  2. Automatically coerced from objects with lat and lng (or lon) properties for point-based queries

The geo::contains() function

The function signature is geo::contains(geoPolygon, geo), which means:

  • First parameter: A polygon region (your boundary/area)
  • Second parameter: A geo point or shape to test if it's inside that boundary

Here's a practical example from the docs:

// For a given $currentLocation geopoint and deliveryZone area
// Return stores that deliver to a user's location
*[
  _type == "storefront" &&
  geo::contains(deliveryZone, $currentLocation)
]

The polygon itself is an array of coordinate pairs (each being a lat/long set). In GeoJSON format, the first and last coordinates should be identical to "close" the polygon.

Other useful geo functions

// Example: Find stores within 10 miles of a location
*[
  _type == 'storefront' &&
  geo::distance(geoPoint, $currentLocation) < 16093.4
]

Note that these geo functions require API version v2021-03-25 or later.

Show original thread
3 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?