gpt4 book ai didi

php - 在 lat/lng 边界框中查找位置

转载 作者:行者123 更新时间:2023-12-03 23:57:46 26 4
gpt4 key购买 nike

我有 4 个变量:

$southwest_lat、$southwest_lng、$northeast_lat、$northeast_lng

我还有一个数据库表,其中包含以下字段:名称、纬度和经度。

// First attempt, likely terribly wrong
$sql = "SELECT * FROM items WHERE
(Latitude >= '$southwest_lat' AND Latitude <= '$northeast_lat') AND
(Longitude >= '$southwest_lng' AND Longitude <= '$northeast_lng')";

如何在坐标形成的边界框中找到 DB 项?

编辑:谢谢大家,更正了查询的经度部分。

最佳答案

您正在将数据库中的纬度和经度与提交值的纬度进行比较。

此外,查询中不需要任何括号,它只会使查询变得困惑和复杂。

你想要这样的东西:

SELECT 
*
FROM
items
WHERE
Latitude >= $southwest_lat AND
Latitude <= $northeast_lat AND
Longitude >= $southwest_long AND
Longitude <= $northeast_long;

关于php - 在 lat/lng 边界框中查找位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5437457/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com