-4

I want to retrieve GPS location of one android device and fetch it to another android device in realtime. I have gone through many resources and came to know that it can be implemented using GCM, FCM, sockets or by polling. However GCM or FCM cannot provide the updates in realtime and polling will lead to more battery drainage. For Sockets I have gone through socket.io implementation but I don't know whether it is the perfect implementation. So please provide suggestions on how to better implement that.

Now another scenario is if multiple users are connected to the server through the same socket then how can we figure which user is monitoring whom ?

Please help...

sam
  • 1,800
  • 1
  • 25
  • 47
  • 1
    There are other categories of apps that offer real-time data exchange between devices. Chats are one example. So, you might consider researching what chat apps use (XMPP, WebRTC, WebSockets, etc.) and consider using one of those technologies. We cannot help you with your socket.io code because we cannot see it. – CommonsWare Sep 08 '17 at 19:25
  • Most of the chat apps implement FCM or GCM but in my case i need to do the same in realtime which can be done via sockets or via other implementation. Chat apps implementing socket has done via socket.io but socket.io does it in a broadcast manner which is suitable for chat rooms but not for private chat. – sam Sep 08 '17 at 19:58
  • "Chat apps implementing socket has done via socket.io" -- that is incorrect. Chat apps can use a wide variety of protocols. I named three in my previous comment: XMPP, WebRTC, and WebSockets. Of those, Socket.IO can help with WebSockets, but it is not the only WebSocket option. Socket.IO can help with other transport mechanisms (e.g., long-polling). So, rather than limiting yourself to Socket.IO, you might consider doing some more research about what other existing apps use. – CommonsWare Sep 08 '17 at 20:12
  • You can also have a look at [MQTT](http://mqtt.org/). – Markus Kauppinen Sep 09 '17 at 12:59

1 Answers1

1

You can use firebase database. Once you get the firebase sdk integrated in your project, sending and getting location updates between devices will be straightforward.

You can save a location entry (lat, lng, timestamp) to the db in one device and in the other you can listen for child events. If the two devices are reading from and writing to the same db reference (say same array) it will work like charm.

Get started here:

https://firebase.google.com/docs/database/android/start/

SafaOrhan
  • 690
  • 9
  • 19