Function: circleRing()
function circleRing(lng, lat, radiusMeters, points): [number, number][]Builds a closed GeoJSON polygon ring approximating a geographic circle.
The ring is computed with an equirectangular approximation: meters are converted to degrees independently per axis, with the longitude scale corrected by the cosine of the latitude. For the radii the SDK works with (tens to hundreds of meters) the metric error is negligible (≤1%) at any latitude where the projection is defined. At extreme polar latitudes, the approximation breaks down, so circles near poles (|lat| > 85°) should be used with caution.
Parameters
lng
number
Longitude of the circle center in degrees.
lat
number
Latitude of the circle center in degrees.
radiusMeters
number
Radius of the circle in meters. Must be positive and finite.
points
number = 64
Number of segments in the ring. Defaults to 64. Non-integer values are floored and the count is clamped to a minimum of 3, the smallest valid GeoJSON linear ring; non-finite values fall back to the default.
Returns
[number, number][]
A closed ring of [lng, lat] positions (first equals last).
Example
import { circleRing } from "@mapvx/web-js"
// Create a 150-meter radius circle ring
const ring = circleRing(-74.006, 40.7128, 150)
const polygon = { type: "Polygon", coordinates: [ring] }
// Custom segments (32 instead of 64) for lower resolution
const coarseRing = circleRing(-74.006, 40.7128, 150, 32)Note
Equirectangular approximation is accurate for radii up to ~500 km and latitudes between approximately ±80°. Beyond these limits, visual distortion may occur near the poles.
Note
Generated rings do not account for geographic obstacles, walls, or buildings. For complex geofencing, consider server-side validation.