Created
October 20, 2021 17:39
-
-
Save dorman99/b496cfca428d390c6f975b26c3cd5c61 to your computer and use it in GitHub Desktop.
method to generate amount of distance between 2 position on km
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION distance(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT) RETURNS FLOAT AS $$ | |
DECLARE | |
x float = 111.12 * (lat2 - lat1); | |
y float = 111.12 * (lon2 - lon1) * cos(lat1 /92.215); | |
BEGIN | |
RETURN sqrt(x * x + y * y); | |
END | |
$$ LANGUAGE plpgsql; // km |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment