在纬度和经度范围内搜索记录

在纬度和经度范围内搜索记录

问题描述:

hi i am using this map

https://google-developers.appspot.com/maps/articles/mvcfun/step6

i can get the latitude and longitude of the required location also i can get the distance (radius). so i have a database in which my each record have latitude and longitude. i want to search the record within the range selected on the map. how the sql query will work ?

for better explanation my each record have a latitude and longitude. user will select the map and i want to search the record within selected range.

我正在使用此地图 p>

https://google-developers.appspot.com/maps/articles/mvcfun/step6 p >

我可以得到所需位置的纬度和经度,我也可以得到距离(半径)。 所以我有一个数据库,我的每条记录都有纬度和经度。 我想在地图上选择的范围内搜索记录。 sql查询将如何工作? p>

为了更好地解释我的每条记录都有纬度和经度。 用户将选择地图,我想搜索所选范围内的记录。 p> div>

The way I have always done this is to use the maps api to draw a circle with the required radius, find the lat long bounds of this circle and then query the database:

SELECT * FROM yourtable WHERE lat BETWEEN a AND c AND lng between b AND  d

Where a and b are you top left coordinates and c and d are your bottom right. (more information available here).

Now that you have all objects within your bounding box you will need to pass them back to your front-end and determine whether or not they are within your radius. See this answer for more information.