这是我的代码,我为 mysql 修改了它的 mysql 函数,现在我们可以直接从 sql 查询中检查我们的 long lat 是否在界限内。
特别感谢CheeseWarlock和Chris Rae的解决方案谢谢先生
select inBounds("58.25173","-100.21041","89.71691425364952","180","-88.9294031317244","-180")
你可以像这样在查询中调用这个函数
DELIMITER $$
CREATE FUNCTION inBounds(pointLat FLOAT, pointLong FLOAT, boundsNElat FLOAT, boundsNElong FLOAT, boundsSWlat FLOAT, boundsSWlong FLOAT) RETURNS VARCHAR(30)
BEGIN
DECLARE westBound FLOAT ;
DECLARE eastBound FLOAT ;
DECLARE inLong FLOAT DEFAULT 0 ;
DECLARE inLat FLOAT DEFAULT 0 ;
IF (pointLong < boundsNElong) THEN
SET eastBound = 1;
End if;
IF (pointLong > boundsSWlong) THEN
SET westBound = 1;
End if;
IF (boundsNElong < boundsSWlong) THEN
IF (eastBound || westBound) THEN
SET inLong = 1;
END if;
ELSE
IF (eastBound && westBound) THEN
SET inLong = 1;
END IF;
END IF;
IF (pointLat > boundsSWlat && pointLat < boundsNElat) THEN
SET inLat = 1;
END IF;
RETURN inLat && inLong;
END$$
DELIMITER ;