ForHosting KIT · Developer Utilities

Total pairwise distance calculator for latitude and longitude points

The total pairwise distance calculator measures the great-circle distance between every unordered pair in a set of geographic points and adds those measurements together.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

It is designed for connectivity analysis, location-network comparison, clustering diagnostics, and any workflow that needs one reproducible measure of how geographically dispersed a point set is. Supply decimal latitude and longitude coordinates, and the result reports the number of points, the number of evaluated pairs, and the combined distance in kilometers, miles, and meters.

What total pairwise distance tells you

Total pairwise distance compresses all direct geographic separations within a point set into one number. For each point, the calculator pairs it with every point that follows it, measures the shortest path over a spherical Earth, and adds that measurement exactly once. With four locations, for example, there are six unordered pairs; reversing a pair does not create another contribution. The result is useful when the question concerns overall spatial spread rather than a route, perimeter, or distance from a chosen center. A compact group produces a smaller total than a widely distributed group containing the same number of locations. Because the total also grows as points are added, compare sets with equal point counts when you want a direct dispersion comparison, or use the reported pair count to derive a mean pairwise distance outside the calculator. Duplicate coordinates are accepted and contribute zero distance to their pair, which preserves the meaning of repeated observations instead of silently removing them.

How the calculation works

Each pair is evaluated with the Haversine formula using a mean Earth radius of 6,371.0088 kilometers. Latitude and longitude are converted from decimal degrees to radians, differences are applied to the spherical formula, and the resulting central angle is multiplied by that radius. This calculates great-circle distance: the shortest surface path on a sphere, not a straight line through Earth and not driving, walking, or network distance. The implementation clamps the intermediate Haversine value to its mathematical range, avoiding floating-point problems for nearly identical or nearly antipodal points. It then accumulates the unrounded kilometer values before producing stable rounded totals in kilometers, miles, and meters. Longitudes may span from -180 to 180, so pairs crossing the antimeridian are handled naturally by the periodic trigonometric calculation. This spherical model is consistent and appropriate for broad connectivity analysis, though a high-precision land survey should use an ellipsoidal geodesic method instead.

Preparing points and interpreting the result

Provide between two and 1,000 records, each containing numeric latitude and longitude fields. Latitude must be between -90 and 90 degrees, while longitude must be between -180 and 180 degrees. Use signed decimal degrees: northern and eastern coordinates are positive, and southern and western coordinates are negative. Do not paste degree symbols, compass letters, or numeric strings, because strict numeric validation prevents ambiguous conversions. The calculator reports n(n−1)/2 pairs, making it easy to confirm that the complete set was evaluated. Remember that a total is sensitive to both geographic spread and the number of observations: doubling a similarly distributed sample can create far more than twice as many pairs. For comparisons across differently sized sets, divide total distance by pair count to obtain the mean pairwise distance, or retain both values in your analysis. At the 1,000-point limit the calculator evaluates 499,500 pairs, providing a practical bound on quadratic work while still supporting substantial site, sensor, or service-area datasets.

Compare facility networks

Measure whether equally sized sets of warehouses, clinics, or offices are geographically compact or dispersed.

Assess cluster cohesion

Use the sum and pair count as inputs to a reproducible mean-distance diagnostic for geographic clusters.

Track sensor deployment spread

Compare snapshots with the same device count to see whether a field network has expanded or contracted.

What does the API request cost?

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

Does each pair get counted twice?

No. Each unordered pair contributes once, so n points produce n(n−1)/2 distance calculations.

Which distance model is used?

The calculator uses the Haversine formula and a mean Earth radius of 6,371.0088 kilometers.

Can I include duplicate coordinates?

Yes. Duplicate records remain in the set, and the distance between identical coordinates contributes zero.

Is this road or travel distance?

No. It measures shortest great-circle surface distance and does not follow roads, borders, terrain, or transit networks.

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/total-pairwise-distance

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/total-pairwise-distance \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points":[{"latitude":0,"longitude":0},{"latitude":0,"longitude":1},{"latitude":1,"longitude":0}]}'
{
  "points": [
    {
      "latitude": 0,
      "longitude": 0
    },
    {
      "latitude": 0,
      "longitude": 1
    },
    {
      "latitude": 1,
      "longitude": 0
    }
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "geo.total_pairwise_distance",
  "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.

min_points2
max_points1000
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 →