Mat*_*att 2 php mapping latitude-longitude
我有4个变量:
$ southwest_lat,$ southwest_lng,$ northeast_lat,$ northeast_lng
我还有一个数据库表,其中包含字段:Name,Latitude和Longitude.
// 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')";
Run Code Online (Sandbox Code Playgroud)
如何在坐标形成的边界框内找到DB项?
编辑:谢谢你们,纠正了查询的经度部分.
您正在比较数据库中的纬度和经度以及提交值的纬度.
此外,查询中不需要任何括号,只会使其变得杂乱无章.
你想要的东西:
SELECT
*
FROM
items
WHERE
Latitude >= $southwest_lat AND
Latitude <= $northeast_lat AND
Longitude >= $southwest_long AND
Longitude <= $northeast_long;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3161 次 |
| 最近记录: |