找到在一定的范围内的项目的给定坐标 [英] Find items within a certain range of given coordinate

查看:246
本文介绍了找到在一定的范围内的项目的给定坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Django的web应用程序存储的位置。

I have a django based web app which stores locations.

我有一个Android手机应用程序,它是直接从Web应用程序的位置和保存位置的Web应用程序。该位置返回到我,我在我的应用程序加载一个mapoverlay。

I have an android mobile app which pulls the locations from the web app and saves locations to the web app. The locations returned back to me I load on a mapoverlay in my app.

我想送我的当前坐标,并返回它们在一定范围内位置的列表。比如我把我的位置,并取回物品2公里半径范围内。 (类似于如何在谷歌API的地方工作,只是在寻找我的数据)。

I would like to send my current coordinates and return a list of locations which are within a certain range. For example I send my location and get back items within a radius of 2km. (Similar to how the Google Places API works, just searching my data).

这可能是最好的发送位置坐标,做这一切的逻辑,我的Python Django应用程序,然后再回到正确的位置列表,只是显示在我的地图上的位置。

It is probably best to send the location coordinates and do all this logic in my python django app, Then return a list of correct locations and just display the places on my map.

我不知道从哪里开始这样做。 我怎样才能筛选出基于关闭一组给定的坐标?一定半径(公里)之内我的存储位置

I don't know where to begin doing this. How can I filter out my stored locations within certain radius(km) based off a given set of coordinates?

推荐答案

半正矢公式是在回答你的问题。然而,它是有点难所以这里解密我为你提供一个简单的解释:

Haversine Equation is the answer to your question. However it is slightly difficult to decrypt so here I provide you with a simple explanation:

要简单地说:

下面的示例/例如,SQL语句会发现最近的20个地点是在25英里半径的37内,-122坐标。它根据该行与目标的纬度/经度的纬度/经度的距离(由纬度/经度以下等式给出)中,然后要求该距离值小于25只行,定购整个查询由距离,并且它限制到20的结果。若要公里而不是英里搜索,与6371.取代3959

Here's the sample/example SQL statement that will find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude (given by lat/lng in the equation below), and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

您可以将SQL转换成任何你想要的。我指的是原理都是一样的。

You can convert the sql to anything you desire. I mean the principle remains the same.

这篇关于找到在一定的范围内的项目的给定坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆