简体   繁体   English

Android算法用于查找给定距离内的所有Geopoints

[英]Android Algorithm for find all Geopoints within a given distance

In my naive beginning Android mind I thought the way to do this would be to loop through each of the objects checking if proximity falls within X range and if so, include the object. 在我天真的Android开头思想中,我认为这样做的方法是遍历每个对象,检查接近度是否在X范围内,如果是,则包括对象。 This is being done with Google Maps and GeoPoints. 这是通过Google地图和GeoPoints完成的。

That said, I know this is probably the slowest way possibly. 也就是说,我知道这可能是最慢的方式。 I did a search for Android Proxmity algorithm's and did not get much really. 我搜索了Android Proxmity算法,并没有真正得到太多。 What I am looking for is best options with regard to this the more efficiently. 我正在寻找的是关于这一点的最佳选择,效率更高。

Are there any libraries I have not been able to find? 有没有找不到的图书馆?

If not, should I load these Location objects into SQL then go from there or keep them in a JSONArray? 如果没有,我应该将这些Location对象加载到SQL中,然后从那里开始或将它们保存在JSONArray中吗?

Once I establish my best datastructure, what is he best method to find all Locations located with X miles of user? 一旦我建立了最好的数据结构,找到位于X英里用户的所有位置的最佳方法是什么?

I am not asking for cut and paste code, rather the best method to this efficiently. 我不是要求剪切和粘贴代码,而是有效地使用它的最佳方法。 Then, I can stumble through the code :) 然后,我可以偶然发现代码:)

My first gut feeling is to group the Locations by regions but I'm not exactly sure how to do this. 我的第一个直觉是按地区分组地点,但我不确定如何做到这一点。

I could potentially have tens of thousands of datapoints. 我可能有数以万计的数据点。

Any help in simply heading in the right direction is greatly appreciated. 非常感谢任何帮助,只是朝着正确的方向前进。

As a side note, I reach this juncture after discovering that a remote API I had been using was.. well.. just PLAIN WRONG and ommiting datapoints from my proximity search. 作为旁注,我在发现我使用的远程API之后就到了这个时刻......好吧......只是PLAIN WRONG并且从我的邻近搜索中省略了数据点。 I also realized that if just placed on the datapoints on the phone, then I could allow the user to run the App without internet connection, and only GPS and this would be a HUGE plus. 我也意识到,如果只是放在手机上的数据点,那么我可以允许用户在没有互联网连接的情况下运行应用程序,只有GPS,这将是一个巨大的优势。 So, with all setbacks come opportunnities! 所以,所有的挫折都会带来机遇!

The answer depends on the representation of the GeoPoints: If these are not sorted you need to scan all of them (this is done in linear time, sorting wrt. distance or clustering will be more expensive). 答案取决于GeoPoints的表示:如果没有对它们进行排序,则需要扫描所有这些(这是在线性时间内完成的,对距离进行排序或者聚类将更加昂贵)。 Use Location.distanceTo(Location) or Location.distanceBetween(float, float, float, float, float[]) to calculate the distances. 使用Location.distanceTo(Location)Location.distanceBetween(float, float, float, float, float[])来计算距离。

If the GeoPoints were sorted wrt. 如果GeoPoints被分类了。 distance to your position this task can be done much more efficiently, but since the supplier does not know your position, I assume that this cannot be done. 到你的位置的距离这个任务可以更有效地完成,但由于供应商不知道你的位置,我认为这是不可能完成的。

If the GeoPoints are clustered, ie if you have a set of clusters with some center and a radius select each cluster where the distance from your position to the cluster's center is within the limit plus the radius. 如果GeoPoints是聚类的,即如果您有一组具有一些中心和半径的聚类,则选择每个聚类,其中从您的位置到聚类中心的距离在限制范围内加上半径。 For these clusters you need to check each GeoPoint contained in the cluster (some of them are possibly farther away from your position than the limit allows). 对于这些群集,您需要检查群集中包含的每个GeoPoint(其中一些可能比限制允许的位置更远离您的位置)。 Alternatively you might accept the error and include all points of the cluster (if the radius is relatively small I would recommend this). 或者,您可以接受错误并包括群集的所有点(如果半径相对较小,我会建议这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查找距给定 Lat Lng 位置一定距离内的所有纬度经度位置 - find all Latitude Longitude locations within a certain distance from a given Lat Lng location 给定 3d 空间中的一组点,找到彼此距离内的所有点组 - Given a set of points in 3d space, find all sets of points within a distance of eachother 如何根据android地图中的最近距离对Geopoints的arraylist进行排序? - How to sort the arraylist of Geopoints based on the nearest distance in android maps? 查找条件为给定N的所有排列的算法 - Algorithm to find all permutations of a given N with condition 检索最近的地理点(纬度/经度)到用户给出的地理点的最佳方法,我有一个存储在MySQL数据库中的所有地理点的列表 - Best way to retrieve nearest geopoints (lat/long) to the one given by user, i have the list of all geopoints stored in a MySQL database 查找给定类的所有子类 (Android) - Find All Subclasses of a given class (Android) 程序无输出,无法找到给定范围内的所有回文数 - No output from program to find all palindrome numbers within a given range 修改Levenshtein距离算法不计算所有距离 - Modifying Levenshtein Distance algorithm to not calculate all distances 在给定角度和距点的距离的情况下找到坐标 - Find the coordinate given the angle and distance from a point 给定距离计算所有可能的路径 - Compute All Possible Paths Given A Distance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM