ForHosting KIT · Developer Utilities

Geometric median calculator

The geometric median is the location that minimizes the sum of straight-line distances to every supplied point.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Unlike the arithmetic mean, it is resistant to a distant outlier, which makes it useful for choosing a representative center for facilities, observations, or planar coordinates. This calculator starts at the centroid and applies deterministic Weiszfeld refinement until the center moves less than your tolerance or reaches the iteration limit. It reports the estimated center, its total distance, and convergence details so you can judge the result instead of accepting an unexplained coordinate.

Choose the geometric median when distance is the objective

A centroid balances coordinate values, but it does not directly minimize travel. One remote point can pull an arithmetic average far away from the dense part of a data set. The geometric median calculator instead searches for the point with the smallest sum of Euclidean distances to all observations. That distinction matters when the coordinate plane represents warehouse positions, service calls, sensor detections, delivery stops, or any other setting where straight-line distance is meaningful. Supply each observation as an object with finite x and y coordinates. Repeated points are allowed and act as repeated observations, so a location appearing five times has five times the influence of a location appearing once. Coordinates are treated as ordinary Cartesian values in the same unit. They are not interpreted as latitude and longitude on a curved Earth. Project geographic data into a suitable planar coordinate system first when accurate physical distance matters. The result is an approximation controlled by an explicit tolerance and iteration cap, rather than a symbolic closed-form answer that generally does not exist.

Understand the Weiszfeld refinement and stopping result

The calculation begins at the arithmetic centroid, then repeatedly forms an inverse-distance weighted average of all input points. Nearby observations receive greater weight during each refinement, moving the estimate toward a location with lower total distance. A modified Weiszfeld step handles the important case where an estimate lands exactly on an input point; the solver checks the geometric optimality condition there instead of dividing by zero. Iteration stops when movement between consecutive estimates is no larger than the requested tolerance. The response includes converged, iterations, and tolerance alongside the center and total_distance. A true converged value means the movement test or an exact-point optimality test succeeded. A false value means the maximum iteration count was exhausted, so the returned center is still the best final iterate but may need another run with a higher cap. A smaller tolerance asks for a more stable coordinate and can require more work. Avoid specifying a tolerance far below the useful precision of your coordinate measurements, because floating-point arithmetic cannot add meaningful accuracy that the source data never contained.

Interpret, verify, and apply the estimated center

Read center.x and center.y in exactly the same coordinate system and units as the submitted points. The total_distance field adds the Euclidean distance from that final center to every observation, which lets you compare candidate data sets or independently verify the objective. For operational decisions, test the output against real constraints: the mathematical center could lie inside a lake, outside a permitted district, or at a site with no road access. The unconstrained geometric median is therefore a strong reference point, not automatically a deployable address. If you must select one of the supplied points, calculate the distance sum for eligible candidates and use this estimate to guide the search; this endpoint does not snap to an observation. Results are deterministic for identical JSON input, tolerance, and iteration limit, with no random initialization or network dependency. Keep all coordinates on a comparable scale, since mixing meters on one axis with degrees or categories on another makes Euclidean distance meaningless. When tracking results over time, store the convergence fields with the coordinate so reviewers can distinguish a completed refinement from an estimate stopped by its configured computational limit.

Place a shared service point

Estimate a central planar location that minimizes aggregate straight-line distance to customer or facility coordinates.

Summarize clustered observations

Find a robust representative center that is less distorted by a remote observation than the coordinate mean.

Initialize a constrained search

Use the unconstrained median center as a reference when evaluating nearby eligible sites or candidate points.

What does the API request cost?

Each API request costs $0.002; the browser calculator can run the same deterministic logic locally.

Is the geometric median the same as the centroid?

No. The centroid averages coordinates, while the geometric median minimizes the sum of Euclidean distances.

Can I submit latitude and longitude?

The solver treats coordinates as a flat Cartesian plane. Project geographic coordinates appropriately before using them for physical-distance decisions.

What happens when points are repeated?

Every array entry is an observation, so repeated coordinates receive proportionally greater influence.

What does converged false mean?

The solver reached max_iterations before satisfying its stopping test; increase the cap or loosen the tolerance if appropriate.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/geo/median-center

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/geo/median-center \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points":[{"x":0,"y":0},{"x":4,"y":0},{"x":2,"y":3}]}'
{
  "points": [
    {
      "x": 0,
      "y": 0
    },
    {
      "x": 4,
      "y": 0
    },
    {
      "x": 2,
      "y": 3
    }
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "geo.median_center",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →