简体   繁体   English

使用Android GPS检测并连接其他手机

[英]Use Android GPS to detect and connect with other phones

So I asked something similar yesterday and did receive an answer to my question, however I don't really think I asked it correctly and therefore didn't receive the exact information I needed. 所以昨天我问了类似的问题并确实收到了我的问题的答案,但是我并不认为我没有正确地问它,因此没有收到我需要的确切信息。

I'm in search of an API, some open source code, or even just a way that someone else has achieved this on the Android. 我正在寻找API,一些开源代码,甚至是其他人在Android上实现这一目标的方式。 I'm making an app that needs to find all other Android devices within a specified radius. 我正在制作一款需要在指定范围内找到所有其他Android设备的应用。 For example, when you open your Android Google Maps App, and you search for say "Restaurants [ZipCode]", it uses a radius modified from your zip code and finds all of those places. 例如,当您打开Android Google地图应用并搜索“餐馆[ZipCode]”时,它会使用从您的邮政编码修改的半径并查找所有这些地点。 The GPS gets YOUR location, and maps uses that information to find restaurants within an address close to that passed in location. GPS获取您的位置,并且地图使用该信息来查找靠近通过位置的地址内的餐馆。

Instead, I want to be able to use the GPS to find my location (as it can now easily), but instead of finding things on a map (which is already built in), I want to be able to find other GPS enabled Android phones. 相反,我希望能够使用GPS找到我的位置(现在可以很容易),但不是在地图上找到东西(已经内置),我希望能够找到其他支持GPS的Android手机。 I get that they will have to be broadcasting their GPS signal at the same time as well (since they don't have their data stored with some sort of central database as a restaurant would). 我得知他们必须同时播放他们的GPS信号(因为他们没有像餐馆那样将数据存储在某种中央数据库中)。 However, I don't just want to FIND these phones, I want to send/receive data from these phones (with correct permissions obviously). 但是,我不只是想找到这些手机,我想从这些手机发送/接收数据(显然具有正确的权限)。

Now, I've found things like the Bump API. 现在,我发现了像Bump API这样的东西。 However, BUMP uses the phones sensors to spark this search. 但是,BUMP使用手机传感器来激发这种搜索。 So basically, if you "bump" your phone with another and have the app running, it will THEN go ahead and use GPS to find the location of the other phone you just bumped with and exchange data between them. 所以基本上,如果你用另一个“碰撞”你的手机并让应用程序运行,它就会继续使用GPS来找到你碰到的另一部手机的位置并在它们之间交换数据。 This is like EXACTLY what I want to do however in their API, they do not provide the functionality to just say, "Hey, give me all phones within a mile from me." 这就像我想要做的那样,但是在他们的API中,他们没有提供只是说“嘿,给我一英里之外的所有手机”的功能。

I've also found API's that can do exactly what I need but they have to be on the same Bluetooth range or on the same Wi-Fi network, which doesn't suit what I need at all. 我还发现API可以完全满足我的需要,但它们必须位于相同的蓝牙范围或相同的Wi-Fi网络上,这根本不适合我的需要。

Do you guys know of anything that can fit exactly what I need that already exists? 你们知道任何能够完全符合我需要的东西吗? Or a way to maybe modify Bump API (if you've done it), to not have to use the phone sensors and find phone information directly through GPS for phones around you? 或者可以修改Bump API(如果你已经完成),不必使用手机传感器直接通过GPS为你周围的手机查找手机信息? Or is there something that exists over a 3g/4g network instead of only wi-fi/Bluetooth? 或者有什么东西存在于3g / 4g网络而不是只有Wi-Fi /蓝牙?

Thanks guys. 多谢你们。

Instead of frequently posting locations to an external server, couldn't the GPS realize other things broadcasting a GPS signal at a very specific time and send/receive data from them? 而不是频繁地将位置发布到外部服务器,GPS不能实现在非常特定的时间广播GPS信号并从它们发送/接收数据的其他事物吗?

The only things that are "broadcasting a GPS signal" are satellites. 唯一的“广播GPS信号”是卫星。

We would like to accomplish this without the use of an external server. 我们希望在不使用外部服务器的情况下实现这一目标。

You have no choice but to use an external server, whether you like it or not, both for discovery and for later communication. 您别无选择,只能使用外部服务器,无论您是否喜欢,都可以用于发现和以后的通信。

Do you guys know of anything that can fit exactly what I need that already exists? 你们知道任何能够完全符合我需要的东西吗?

Foursquare , Google Latitude , Yahoo Fire Eagle , and so on. Foursquare谷歌纵横雅虎火鹰等。

To do this via GPS, you would have to have all the phones frequently posting their locations to a network server, which could then inform them of others nearby. 要通过GPS执行此操作,您必须经常将所有手机的位置发布到网络服务器,然后通知他们附近的其他人。

Needless to say this would be opt-in only! 毋庸置疑,这只是选择加入!

And it may have negative consequences for battery life, unless you make it update infrequently, which may limit its usability. 它可能会对电池寿命产生负面影响,除非您不经常更新,这可能会限制其可用性。

The advantage of having an explicit trigger action to both phones is that they only need to query the GPS and inform the server to find each other by location when they've both been triggered. 对两部手机采取明确的触发操作的优点是,他们只需要查询GPS并通知服务器在触发时按位置找到对方。

The question now has a very simple solution to it. 现在的问题有一个非常简单的解决方案。 All you have to do is set up a Geofence and monitor it for entry and exit of users. 您所要做的就是设置Geofence并监控它以进入和退出用户。 Geofence allows you to choose a geolocation and set a circle of desired radius around it. 地理围栏允许您选择地理位置并在其周围设置所需半径的圆。 When someone enters or exits the location you can get notified and perform desired action. 当有人进入或离开该位置时,您可以收到通知并执行所需的操作。

Visit this link for further details on how to use this in Android. 有关如何在Android中使用此功能的详细信息,请访问此链接

You would probably have to author your own application - then you could do this server-side and push things. 您可能需要编写自己的应用程序 - 然后您可以执行此服务器端并推送事物。 If you're trying to push data to random Android phones - you're out of luck. 如果您正在尝试将数据推送到随机Android手机 - 那你就不走运了。 Most people aren't going to want this, and probably aren't going to have the apps necessary to receive and understand it. 大多数人都不会想要这个,并且可能不会拥有接收和理解它所需的应用程序。 With Bluetooth networking you'd need authorization, and most Androids don't have a capability to transfer random data by Bluetooth out of the box (though you certainly can get software to do it). 使用蓝牙网络,您需要授权,并且大多数安卓都无法通过蓝牙开箱即可传输随机数据(尽管您当然可以获得软件)。

Honestly, malware and tracking are the reasons this really isn't possible, but even if they weren't, you would still need an application on the receiving devices that understand what you're sending them. 老实说,恶意软件和跟踪是真正无法实现的原因,但即使它们不存在,您仍然需要接收设备上的应用程序才能了解您发送的内容。 And if you're widely spread enough, you'd probably want to send it to a server to disseminate anyway (for the transmitting phones bandwidth costs at least). 如果你的传播范围很广,你可能想把它发送到服务器来传播(至少对于传输电话的带宽成本)。

Develop a server application that your android app logs into. 开发Android应用程序登录的服务器应用程序。 Send the GPS location every time the phone moves over a present distance. 每次手机移动到当前距离时发送GPS位置。 Either send a query request to the server to ask it if any other phones are in range, or get the server to inform the phone of a new device in range. 向服务器发送查询请求以询问是否有其他电话在范围内,或让服务器通知电话范围内的新设备。

You may run into server scalability problems, so thats something to think about. 您可能会遇到服务器可伸缩性问题,因此需要考虑一些事情。 Also, this would be a big battery drain, and so your users may not be too keen to run it, not to mention the privacy element. 此外,这将是一个很大的电池消耗,因此您的用户可能不会太热衷于运行它,更不用说隐私元素了。

You need to rethink what you're trying to do. 你需要重新思考你想要做的事情。 Android devices don't "transmit" any GPS signal, they are simply receivers, with signals from satellites. Android设备不会“传输”任何GPS信号,它们只是接收器,来自卫星的信号。 So the phone can easily get a location for itself, but the location of other devices is very, very private information. 因此手机可以轻松获得自己的位置,但其他设备的位置是非常非常私密的信息。 To get access to location for other phones, you either need to be on the same network as them (bluetooth, wifi), or you need them to use a server-based service to send locations to, like Google Latitude. 要访问其他手机的位置,您需要与他们在同一网络(蓝牙,wifi),或者您需要使用基于服务器的服务来发送位置,例如谷歌纵横。

I'd be highly unlikely to sign up to a service like that. 我不太可能注册这样的服务。 My location is very private, I share it with some people, but I cannot seem myself openly sharing it with an app, without a very, very good reason. 我的位置非常私密,我与一些人分享,但我似乎无法公开分享它与应用程序,没有非常,非常好的理由。

It seems to me that you need to build a server-based application, eg on Google App Engine, have people sign up, and agree to their location being sent to that server, so other phones running your app can access that information from the central store. 在我看来,您需要构建基于服务器的应用程序,例如在Google App Engine上,让人们注册,并同意将他们的位置发送到该服务器,因此运行您的应用程序的其他手机可以从中央访问该信息商店。

All the comments from other folks about not being able to pick up the signal from others phones are correct. 其他人关于无法从其他手机接收信号的所有评论都是正确的。 There is a completely different alternative system however in the network based location services. 然而,在基于网络的位置服务中存在完全不同的替代系统。 This is a model where you ask a carrier network for the location of a handset, which the carrier network needs to track for enhanced 911 service in the US (I'm unaware of how widely deployed this is in other areas, and how many different services you would need to use to cover other areas). 这是一个模型,您可以向运营商网络询问手机的位置,运营商网络需要跟踪其在美国的增强型911服务(我不知道这在其他领域的部署程度如何,以及有多少不同您需要用来覆盖其他区域的服务)。

It's potentially a very expensive route however. 然而,这可能是一条非常昂贵的路线。 And it won't just automatically work for all handsets, I believe the users will have to be opted into sharing location with your service. 它不仅会自动适用于所有手机,我相信用户必须选择与您的服务共享位置。 This is how services like Loopt had initially setup their location info so that it could be passively collected without negatively impacting handset battery life. 这就是Loopt等服务最初设置其位置信息的方式,以便可以被动地收集而不会对手机电池寿命产生负面影响。 There are some third party services that front for a cross-carrier service such as Location Labs: 有一些第三方服务可用于跨运营商服务,例如Location Labs:

http://locationlabs.com/ http://locationlabs.com/

As well as third party location services like Skyhook Wireless, who might be able to get you some info of the sort (though I don't think what you're looking for maps to any of their existing APIs) 除了像Skyhook Wireless这样的第三方定位服务,他们可能能够为您提供某种类型的信息(尽管我不认为您正在寻找的是他们现有API的地图)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM