如何在android中查找附近的应用用户? [英] How do I find nearby app users in android?

查看:152
本文介绍了如何在android中查找附近的应用用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,它需要能够找到附近的人,他们是我应用程序的用户。

我查看了许多类似先例的问题的答案,似乎我别无选择,继续上传用户的当前位置到服务器,并在必要时获取附近用户的列表。

然后我的问题是,

1.要得到附近的列表,应该有一些算法或函数来计算距离。那么这并不意味着我必须获得我的位置和其他应用程序用户之间的所有距离吗?所以服务器返回一定数量的距离最短的用户。如果我是正确的,是不是会有记忆或时间问题?

2.这可能听起来很奇怪,但这个怎么样。

我可能会发送经纬度信息或地址信息到服务器。我无法将这些字符串与使用字符串搜索算法的第一个数字或字母的所有用户的地址列表进行比较吗?

例如,如果我最后一次更新的地址在服务器上是'abcde',算法将查找以'a'开头的地址,如果搜索完成,然后查找在'a'之后具有'b'的地址,换句话说'ab'。

这可能不是一个正确的解决方案,但我认为它可能会工作,因为地址将以相同的形式保存。

解决方案

需要一个空间索引。请参阅:分层三角网格



您也可以使用支持空间查询的数据库之一


我可能会向服务器发送经纬度信息或地址信息。我无法将这些字符串与使用字符串搜索算法的第一个数字或字母的所有用户地址列表进行比较吗?

将不会与纬度和经度一起工作,因为这样你只能在一个维度上搜索接近度。例如,30°N 30°E将出现在接近30°N 90°E的地方,而不是31°N 30°E。

它可以与地址一起工作,但前提是它们必须与坐标可靠连接(即不能由用户键入),并且只有在您不介意用户200相距几米,但在某些行政边界的不同方面不会相互接近。

I am making an application which needs to be able to find people nearby, who are users of my app.
I looked at many answers of precedent similar questions, and it seems I have no choice but to keep uploading a user's current location to the server, and get nearby users' list when necessary.

Then my question is,
1. To get the nearby list, there should be some algorithm or function which calculates the distance. Then doesn't that mean I have to get all distances between my location and the rest of the app users? So the server returns certain number of users who have the least distance results. If I'm correct, wouldn't there be memory or time issues?
2. This might sound weird, but how about this.
I'll probably send latitude and longitude information or address information to the server. Can't I compare those strings with all users' address list from the first numbers or letters using string searching algorithms or something?
For example, if my last updated address is 'abcde' on the server, the algorithm will look for addresses that start with 'a', if finished searching, then look for addresses that has 'b' after 'a', in other words 'ab'.
This might not be a right solution, but I thought it might work because the address will be saved in same forms.

解决方案

To find nearby users efficiently, you need a spatial index. See: Hierarchical Triangular Mesh.

You also can use one of the databases that support spatial queries.

I'll probably send latitude and longitude information or address information to the server. Can't I compare those strings with all users' address list from the first numbers or letters using string searching algorithms or something?

That won't work with latitude and longitude because that way you can only search for proximity in one dimension. For example, 30°N 30°E will appear closer to 30°N 90°E than to 31°N 30°E.

It may work with addresses, but only if they are reliably connected with coordinates (i.e. not typed in by users), and only if you don't mind that users 200 meters apart but on different sides of some administrative border will not count as close to each other.

这篇关于如何在android中查找附近的应用用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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