Skip to content

Comments

feat: getGeoDiff#40

Merged
DoneDeal0 merged 4 commits intomainfrom
getgeodiff
Feb 22, 2026
Merged

feat: getGeoDiff#40
DoneDeal0 merged 4 commits intomainfrom
getgeodiff

Conversation

@DoneDeal0
Copy link
Owner

@DoneDeal0 DoneDeal0 commented Feb 15, 2026

🌎 NEW FEATURE: getGeoDiff

import { getGeoDiff } from "@donedeal0/superdiff";

Returns a structured diff between two geographical coordinates. Supports 9 distance units, locale‑aware output, and two accuracy modes.

  • High‑accuracy mode is based on the Vincenty formulae (ellipsoidal Earth model, higher precision).
  • Normal-accuracy mode is based on the Haversine formulae (spherical Earth model, faster, slightly less precise).

FORMAT

Input

  previousCoordinates: [number, number] | null | undefined;
  coordinates: [number, number] | null | undefined;
  options?: {
    unit?: "centimeter" | "foot" | "inch" | "kilometer" | "meter" | "mile" | "mile-scandinavian" | "millimeter" | "yard"; // "kilometer" by default
    accuracy?: "normal" | "high"; // "normal" by default
    maxDecimals?: number; // 2 by default,
    locale?: Intl.Locale | string; // "en-US" by default
  }
  • previousCoordinates: the original coordinates ([Longitude, Latitude]).
  • coordinates: the new coordinates ([Longitude, Latitude]).
  • options
    • unit: the unit used for the returned distance.
    • accuracy:
      • normal (default): fastest mode, with a small error margin, based on Haversine formula.
      • high: slower but highly precise distance. Based on Vincenty formula.
    • maxDecimals: maximal decimals for the distance. Defaults to 2.
    • locale: the locale of your distance. Enables a locale‑aware distance label.

Output

type GeoDiff = {
    type: "geo";
    status: "added" | "deleted" | "error" | "equal" | "updated";
    diff: {
        coordinates: [number, number] | null;
        previousCoordinates: [number, number] | null;
        distance: number;
        unit: "centimeter" | "foot" | "inch" | "kilometer" | "meter" | "mile" | "mile-scandinavian" | "millimeter" | "yard";
        label: string,
        direction: "east" | "north" | "south" | "west" | "north-east" | "north-west" | "south-east" | "south-west" | "stationary";
    };
}

USAGE

Input

getGeoDiff(
- [2.3522, 48.8566],
+ [-0.1278, 51.5074]
);

Coordinates follow GeoJSON order: [longitude, latitude].

Output

{
      type: "geo",
+     status: "updated",
      diff: {
+          coordinates: [-0.1278, 51.5074],
           previousCoordinates: [2.3522, 48.8566],
+          direction: "north-west",
+          distance: 343.56,
+          label: "343.56 kilometers",
+          unit: "kilometer"
        }
}

See our website documentation

@DoneDeal0 DoneDeal0 changed the title feat: getGeoDiff [DRAFT] feat: getGeoDiff Feb 15, 2026
@DoneDeal0 DoneDeal0 self-assigned this Feb 15, 2026
@DoneDeal0 DoneDeal0 force-pushed the getgeodiff branch 7 times, most recently from d6fab17 to e4d374b Compare February 21, 2026 11:13
@DoneDeal0 DoneDeal0 force-pushed the getgeodiff branch 2 times, most recently from aeecdc1 to 7a20d16 Compare February 22, 2026 10:12
@DoneDeal0 DoneDeal0 changed the title [DRAFT] feat: getGeoDiff feat: getGeoDiff Feb 22, 2026
@DoneDeal0 DoneDeal0 marked this pull request as ready for review February 22, 2026 10:16
@DoneDeal0 DoneDeal0 merged commit 6666f4f into main Feb 22, 2026
1 check passed
@DoneDeal0 DoneDeal0 deleted the getgeodiff branch February 22, 2026 10:40
@github-actions
Copy link

🎉 This PR is included in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant