Understanding regions/geopolygon for geopoint queries in Sanity
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:
- Created from a GeoJSON object with a
typeproperty set to "Polygon" (or other geometry types like "MultiPolygon") - Automatically coerced from objects with
latandlng(orlon) 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
geo::distance(point1, point2): Returns distance in meters between two points (only works with points, not polygons)geo::intersects(geo1, geo2): Checks if two geographic areas overlapgeo::latLng(lat, lng): Quick helper to create a point from coordinates
// 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 thread3 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.