Geodesy on the globe (Spherical)
Distance, heading, area and interpolation, with the same names and the same results on all three platforms. Nothing depends on a map SDK utility, so swapping providers never changes a number — and the SDK own hit testing and great-circle rendering use exactly these functions.
01 · The basics
The everyday functions live under Spherical. Distances come back in metres, headings in degrees clockwise from true north, areas in square metres. Inputs are plain coordinates — no projection or zoom involved.
val meters = Spherical.computeDistanceBetween(from, to)
val heading = Spherical.computeHeading(from, to)
// 円の外周マーカーを8方向に置く
val ring = (0 until 8).map { i ->
Spherical.computeOffset(center, 3_000.0, i * 45.0)
}
val routeMeters = Spherical.computeLength(routePoints)
val areaSqMeters = Spherical.computeArea(polygonPoints)let meters = Spherical.computeDistanceBetween(from: from, to: to)
let heading = Spherical.computeHeading(from: from, to: to)
let ring = (0..<8).map { i in
Spherical.computeOffset(origin: center, distance: 3_000.0, heading: Double(i) * 45.0)
}
let routeMeters = Spherical.computeLength(routePoints)import { computeDistanceBetween, computeOffset, computeLength } from '@mapconductor/js-sdk-core';
const meters = computeDistanceBetween(from, to);
// 中心から 3km、45度きざみのリング
const ring = Array.from({ length: 8 }, (_, i) =>
computeOffset({ origin: center, distance: 3000, heading: i * 45 }));
const routeMeters = computeLength(routePoints);02 · Sphere and ellipsoid
Two levels of accuracy are available: a spherical model treating the Earth as a perfect sphere, and a geodesic model on the WGS84 ellipsoid.
Both use WGS84 constants (equatorial radius 6,378,137 m, flattening 1/298.257223563). The same constants and formulas on all three platforms mean identical inputs give identical outputs.
Spherical — fast and accurate enough
Haversine distance plus spherical trigonometry for headings and interpolation. Up to a few hundred kilometres the error is negligible in practice, and it is cheap to compute.
Ellipsoidal — true geodesics
Computes on WGS84 geodesics via an iterative (Vincenty-family) solution. It exposes the same method set as Spherical, so you can swap Spherical (globe) for WGS84Geodesic (WGS84) without changing call sites. Area is computed on the ellipsoid (authalic sphere).
Falls back to the sphere when iteration fails
The iterative solution may not converge for near-antipodal pairs. It then falls back to the spherical result, so you never get 0 or NaN and never need error handling at the call site.
03 · Bridging to the screen
These convert screen-based amounts — a fingertip, a 16 px margin — into geographic distance. Zoom and latitude are part of the conversion, so the feel stays the same wherever you are and however far you are zoomed in.
04 · For lines and shapes
These make polyline and polygon rendering and hit testing identical across providers. They are the very functions the SDK uses internally.
createInterpolatePoints and pointOnLineOrNull exist under both WGS84Geodesic and Planar with identical names, so swapping the namespace is all it takes to move between the geodesic and straight-line models.
Identical inputs, identical results
The Kotlin, Swift and TypeScript implementations share formulas and constants, so distances and areas never disagree between platforms.
Yours to use as well
The core computation functions are not internal-only — use them directly for route distances, radius maths or your own hit testing. Every function listed on this page is present on all three platforms.