在MySQL数据库中搜索用于输入经纬度的值 [英] Searching a MySQL database for values serving the input lat/long
本文介绍了在MySQL数据库中搜索用于输入经纬度的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题不同于常规的基于纬度的mysql lat/long/radius数据获取
This question is different from regular mysql lat/long, radius based data fetching
我想搜索一个包含以下列的mysql数据库表,例如-
I want to search a mysql database table which contains following columns for example-
ID Items lat long serving_radius(in km)
1 Item1 26.120888 85.364723 2
2 Item2 26.120888 85.364723 5
3 Item3 25.859800 85.786598 4
4 Item4 26.594900 85.504799 8
现在,如果用户的经/纬度为(29.941095/77.812424),则想知道可以在他的位置提供这些商品中的哪些商品.然后,我将如何使用php&获取结果. MySQL的.
Now if a user has lat/long (29.941095/77.812424) wants to know which of these items can be served at his location. Then how i will fetch the result using php & mysql.
推荐答案
"serving_radius"是否已存储在您的表中? 您可以做的就是获取距离,并检查它是否在serving_radius下
Is "serving_radius" already stored in your table ? What you can do is fetch distance and check if its under serving_radius
SELECT serving_radius,
(6371 * acos(cos(radians(" . $userLatitude . ")) * cos(radians(`latitude`)) * cos(radians(`longitude`) - radians(" . $userLongitude . ")) + sin(radians(" . $userLatitude . ")) * sin(radians(`latitude`)))) as distance
having distance < serving_radius
这篇关于在MySQL数据库中搜索用于输入经纬度的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文