Skip to content

Instantly share code, notes, and snippets.

@almeida1492
Created June 30, 2022 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almeida1492/1ea2780155bebc47659aafcd3f22450b to your computer and use it in GitHub Desktop.
Save almeida1492/1ea2780155bebc47659aafcd3f22450b to your computer and use it in GitHub Desktop.
import { ICoordinates } from "../types";
export const getIsWithinRange = (
claimantCoordinates: ICoordinates,
reportCoordinates: ICoordinates
): boolean => {
const rangeRadius = 0.0008695277120173415;
const deltaLat = reportCoordinates.lat - claimantCoordinates.lat;
const deltaLng = reportCoordinates.lng - claimantCoordinates.lng;
const squareLegLat = Math.pow(deltaLat, 2);
const squareLegLng = Math.pow(deltaLng, 2);
const hypotenuse = Math.sqrt(squareLegLat + squareLegLng);
return hypotenuse <= rangeRadius;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment