Reputation: 33
I have tried to implement store procedure
DELIMITER $$
CREATE PROCEDURE FindRadius(IN stop_lat float,IN stop_lng float,IN lat float,IN lng float,OUT radius float)
BEGIN
declare R INT DEFAULT 6371;
declare dLat float;
declare dLon float;
declare a float;
declare c float;
dLat = RADIANS(stop_lat-lat);
dLon = RADIANS(stop_lng-lng);
a = SIN(dLat/2) * SIN(dLat/2) +COS(RADIANS(stop_lat)) * COS(RADIANS(lat)) * SIN(dLon/2) *SIN(dLon/2);
c = 2 * ATAN2(SQRT(a),SQRT(1-a));
SET radius = R * c *1000;
END$$
DELIMITER ;
It is throwing error saying that You have an error in your SQL syntax;
RADIANS(stop_lat-lat); dLon = RADIANS(stop_lng-lng); a = SIN(dLat/2) * SI' at line 8
I have no idea why this error is comming can anyone help
Upvotes: 0
Views: 54
Reputation: 4875
you should not do:
dLat = ....
it should be:
SET dLat = RADIANS(stop_lat-lat);
SET dLon = RADIANS(stop_lng-lng);
SET a = SIN(dLat/2) * SIN(dLat/2) +COS(RADIANS(stop_lat)) * COS(RADIANS(lat)) * SIN(dLon/2) *SIN(dLon/2);
SET c = 2 * ATAN2(SQRT(a),SQRT(1-a));
Upvotes: 1