是否可以找到附近的其他手机?

2022-01-22 00:00:00 gps android java smartphone

我正在编写一个 Android 应用程序,我希望最终将其移植到 iOS 和 Windows Mobile(尽管我现在对它们一无所知).我希望我的应用程序能够在一定半径(可能 20-30 英尺)内找到其他也安装了游戏的手机,以便用户可以在他们当前的物理空间中与其他人互动.这可能吗?如果可以,怎么做?

I'm writing an Android app that I would like to eventually port to iOS and Windows Mobile (though I know absolutely nothing about them right now). I'd like my app to be able to find other phones within a certain radius (maybe 20-30 feet) that also have the game installed so that the users can interact with others in their current physical space. Is this possible and, if so, how?

我计划使用需要互联网连接的应用程序,所以我的第一个想法是使用 GPS,如 iOS 查找其他附近的设备(GPS 位置),但这需要不断地将数据传输到服务器以使用带宽和电池(更不用说服务器资源)来更新用户的位置.GPS 似乎也需要一段时间才能获得任何类型的准确修复,即使我不会存储历史数据,我也不希望用户相信我拥有那种私人信息(他们也不应该!)

I plan on the app requiring an internet connection so my first thought was to use GPS like described at iOS Find Other Nearby Devices (GPS locations), but that would require continually transmitting data to the server to update the user's location using both bandwidth and battery (not to mention the server resources). GPS also seems to take a while to get any sort of accurate fix, and even though I wouldn't store historical data I wouldn't expect users to trust me with that sort of private information (as well they shouldn't!)

我知道有一些专有技术,例如 Sony 的 NFC,但对于我希望与设备和操作系统无关的应用来说,这太狭窄了.还有哪些其他选择?假设用户愿意为应用程序授予适当的权限,还有哪些其他方法可以让一台设备在 10-15 米范围内找到附近的另一台设备,这对于大型(百万+)用户群来说是实用的?HTML5 Geolocation 是更好的路径吗?还是 GPS 是我唯一真正的选择?

I know there are proprietary technologies, such as Sony's NFC, but that's far too narrow a focus to use for an app that I'd like to be device and OS agnostic. What other options are there? Assuming the user is willing to give the app the appropriate permissions, what other methods could allow one device to find another nearby one, within a 10-15 meter range, that is practical for a large (million+) userbase? Is HTML5 Geolocation a better path? Or is GPS my only real option?

我确实找到了 使用 Android GPS 来检测和与其他手机连接,但希望过去几年开辟了更多选择.

I did find Use Android GPS to detect and connect with other phones, but was hoping the past few years have opened up further options.

更新

感谢您迄今为止的所有回复.为了回答评论和答案中提出的一些问题,我想我应该描述一下我希望应用/设备如何交互.

Thank you for all the responses so far. To answer some questions posed in the comments and answers, I thought I'd describe how I expect the apps/devices to interact.

安装此应用的所有用户都将在后台运行一个代理来更新他们当前的地理位置并监听 ping.任何用户都可以打开完整程序并向附近的所有其他用户发送快速请求.如果我使用中央服务器路由,那么服务器会使用附近用户名列表响应该请求.然后,用户可以选择其中一个来启动连接,在这种情况下,目标设备会发出声音来通知连接请求.

All users who install this app will have an agent running in the background to update their current geolocation and to listen for pings. Any user may open the full program and send a quick request for all other users nearby. If I go the central server route, then the server responds to that request with a list of nearby usernames. The user can then pick one of those to initiate a connection, in which case the target device makes a sound to notify of a request to connect.

从那里可以很容易地处理两个设备之间的交互.找到附近的用户是我的症结所在.

From there it's easy enough to handle the interaction between two devices. Finding those nearby users is the sticking point for me.

推荐答案

我能看到的选项

  1. 蓝牙 (BT).我不知道,如果我不太怀疑的话,但我看到了几个问题.短距离.最大的能源消耗.最多同时连接 7 个对等点(但也许就足够了......).最大的优势是很多设备都支持BT.

  1. Bluetooth (BT). I don't know, if I'm not too skeptical about it, but I see couple of problems. Short range. The biggest energy consumption. Maximum 7 peers connected at the same time (but maybe it's enough...). The big advantage is that a lot of devices support BT.

BT LE(低能量).好的,它有助于解决能源消耗问题.但是,需要 Android 4.3.

BT LE (low energy). Ok, it helps energy consumption problem. But, requires Android 4.3.

WiFi 直连(又名 P2P).我试了一下,有点失望.问题是它需要 Android 4.0 或更高版本.更糟糕的是,有些设备不需要硬件.我从三星 Xperia Miro ST23i 上的 Android 示例中启动了 WiFiDirectDemo.单击搜索",我得到的唯一结果是启用 WiFi P2P - 在您的设置中".我点击了该设置中的所有内容,只有普通的 WiFi 和其他内容,没有提及 Direct 或 P2P.Xperio Miro 只是不支持 WiFi Direct.

WiFi Direct (aka P2P). I gave it a shot, I'm a bit disappointed. The problem is that it needs Android 4.0 or higher. Even worse, some devices don't have required hardware. I launched WiFiDirectDemo from Android samples on Samsung Xperia Miro ST23i. Clicked on "search" and the only thing I got was a toast "enable WiFi P2P - in your settings". I clicked on everything in that settings, there is just normal WiFi and other stuff, no mention about Direct or P2P. Xperio Miro just doesn't support WiFi Direct.

通过互联网 + 设备地理定位与服务器的 WiFi 连接. 服务器保持用户的位置并回答诸如谁在我的范围内 20 英尺?"之类的问题.问题可能是地理位置的精度.如果墙壁很厚,或者您所在的地球上卫星很少 - 这可能非常不准确.

WiFi connection with a server through internet + device geolocation. Server keeps positions of users and answers questions like "who is 20 feet in my range?". The problem can be the precision of geolocation. If the walls are thick or you are in a place on earth with few satellites - it can be very inaccurate.

总结一下

与 BT 相比,有人一直打开 WiFi 的可能性更大.BT 也有一些时间限制,之后它就会关闭(他们这样做可能是为了节省电池).所以,WiFi 似乎是比 BT 更好的选择.

To sum up

There is greater probability that somebody will have WiFi turned on all the time than BT. BT also have some time limits after which it is turned off (they make it this way to probably save battery). So, WiFi seems a better choice than BT.

如果 WiFi Direct 对您来说足够受欢迎 - 我会尝试一下.如果没有,选项 4 似乎是最好的.我知道这并不理想,但目前很难找到更好的东西(我们仍然需要技术开发,WiFi Direct 看起来很有希望).

If WiFi Direct is popular enough for you - I would give it a try. If not, option number 4 seems the best. It's not ideal, I know, but at this point it's hard to come with something better (we still need technology development, WiFi Direct looks promising).

相关文章