如何使用同一应用程序检测附近的Android设备 [英] How to detect nearby android devices using the same app

查看:130
本文介绍了如何使用同一应用程序检测附近的Android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我过去曾经制作过一些小型应用程序,但这是我的第一个适当"应用程序.

So basically I have made a few small apps in the past, but this is my first 'proper' app.

该应用程序的主要功能之一,也是让我苦苦挣扎的一点是,我需要能够使用登录到该应用程序的所有其他用户来填充ListView,但是我只想向用户显示在设定的距离之内,例如10米之内.

One of the main features of the app, and the bit that I am struggling with is that I need to be able to populate a ListView with all of the other users logged into the app, however I only want to display users that are within a set distance, for example 10 meters.

我尝试使用蓝牙来实现此目的,但是那没有用.我现在想使用位置服务来做到这一点.

I tried using Bluetooth to achieve this, however that didn't work. I would now like to use location services to do this.

我的想法是必须每隔几分钟将应用的位置发送到外部服务器,然后所有其他设备都可以运行将其位置与该服务器上其他位置进行比较的功能.

My idea is to have to app send the location of the device to an external server every few minutes and then all other devices can run a function that compare their location to others found on this server.

有人知道我如何实现这一目标,或者知道任何涉及更简单主题的教程.谢谢

Does anybody know how I could go about achieving this, or know of any tutorials that cover a simpler topic. Thank you

推荐答案

免责声明:我不是android开发人员,但这似乎是设计问题,不是实现问题,因此希望我在下面的评论可能有一定用处...

Disclaimer: I'm not an android developer, but this seems like a design issue not a implementation issue so hopefully my comments below might be of some use...

我不认为可以将API设置为"true"来获得此功能,因此我认为您将必须定制所有运动部件(并且有几个).我认为总体过程将是这样的:

I don't think there's an API that you can just set to "true" to get this functionality, so I think you're going to have to custom craft all the moving parts (and there are a couple). I would think the general process would be something like:

  1. 客户端上的用户以某种身份(即"user@gmail.com")登录服务器
  2. 客户端应用每隔X分钟获取当前位置(即"100N 90E")并将其发送到服务器
  3. 客户端每隔X分钟轮询服务器以查看谁在10英里范围内(即"joe@gmail.com","mary@gmail.com")

在服务器上:

  1. 需要某种身份验证端点才能获取用户的身份
  2. 需要一个端点供用户注册其位置("user@gmail.com位于100N 90E")
  3. 需要一种服务来找出每个用户之间的距离
  4. 需要端点返回X英里内的用户(由#3生成的列表)

这些步骤中的每一个都不是一件容易的事,如果您愿意的话,您实际上可以在服务器步骤3上使用分发算法获得一些好处.

Each one of these steps shouldn't be difficult on their own and you can actually get pretty nuts with the distribution algorithm on server step #3 if you wanted to.

您可以问自己一些问题:

Some questions you can ask yourself are:

  • 如何设置服务器以侦听HTTP请求?" -查看Node.JS以获得简单的解决方案
  • 如何在android中获取用户的位置?" -简易的Google搜索可找到大量文档
  • 如何编写服务以连续执行操作?" -Node.JS会再次为此提供帮助
  • 我将在哪里存储用户的位置及其彼此之间的距离?" -您可以查看NoSQL选项,例如CouchBase或MongoDb.或者,您可以将MySQL用于更结构化的数据库.

希望这对您有帮助...

Hope this helps...

这篇关于如何使用同一应用程序检测附近的Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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