long lat

example

http://www.movable-type.co.uk/scripts/latlong.html

 

CREATE DEFINER = \’root\’@\’%\’
FUNCTION test.function3(lat1 FLOAT(10,6), lon1 FLOAT(10,6), lat2 FLOAT(10,6), lon2 FLOAT(10,6))
  RETURNS int(11)
BEGIN
DECLARE R INT DEFAULT 6371; — // km
DECLARE dLat FLOAT(10,6);
DECLARE dLon FLOAT(10,6);
DECLARE a, d, c FLOAT(10,6);
DECLARE pi80 FLOAT(10, 6);
 
SET pi80 = PI() / 180;

SET dLat = (lat2-lat1) * pi80;
SET dLon = (lon2-lon1) * pi80;
SET lat1 = lat1 * pi80;
SET lat2 = lat2 * pi80;

SET a = SIN(dLat/2) * SIN(dLat/2) + SIN(dLon/2) * SIN(dLon/2) * COS(lat1) * COS(lat2);
SET c = 2 * ATAN2(SQRT(a), SQRT(1 – a));
SET d = R * c;

RETURN d;
END

 

SET @lat1 = 49.990509;
SET @lon1 = 36.223447;
SET @lat2 = 50.464509;
SET @lon2 = 30.685721;
SET @ResultValue = test.function3(@lat1, @lon1, @lat2, @lon2);
SELECT @ResultValue;

Leave a Reply

Your email address will not be published. Required fields are marked *