Reputation: 2172
Basically I want to track another device using Google Maps with the help of a GPS. Can you give me an advice on how I could do it efficiently?
What I have in mind is: I will write the longitude and latitude of the device I want to track in a remote database. And the other will fetch the data every 5 sec or something.
Is that efficient? Or there are other ways to send the coordinates directly to the other device?
Thanks!
Upvotes: 0
Views: 368
Reputation: 5049
I propose setting the location change listener to react on a minimum distance, not only on time interval. The posting client may be static for some time, fetching GPS and sending it is a waste of cpu time, bandwidth and battery.
Also, 5 seconds can be a short time. It can drain battery and consume bandwidth quite fast.
If you are certain you have to track the client always when the application is started, then a periodical post is ok. If the receiving phone only needs the location from time to time, than a pull request would be more economical (i.e he should request the location from another phone).
And finally, this might be handy: http://googlecloudplatform.blogspot.com/2013/06/get-your-mobile-application-in-the-cloud-with-mobile-backend-starter.html . The example is actually something you are building, of not the same.
P.S There is no way to send data "directly" to another phone (except if it is always connected to the same hotspot with a public IP address and reserved local IP, which is not the case 99% of the time). That means you should use Google Cloud Messaging or a similar implementation.
Upvotes: 1
Reputation: 1036
I think best use push notification, server send to device command 'Give me your location' and device answer server via http query, also easy change fetching data from 5 sec to 30, for example.
Upvotes: 0
Reputation: 13815
Choice depends on the time interval selected for location submission and its polling from other client.
If its every 3 minute (Realistic i feel) or more. I guess normal http submission to your remote server and fetching the same using http could do the trick. That would be super easy implementation to what you want to achieve.
But if you are looking for something real time like instant messaging thing. You have to go for xmpp connections. openfire server implementation and smack library could be helpful for you.
here are the links.
Download server from here
http://www.igniterealtime.org/projects/openfire/
check client code from here
http://developer.samsung.com/android/technical-docs/Building-a-Chat-Application
Replace google credentials with your local openfire server created one and ip and port respectively.
Following the above two only. I created a simple chat application for android along with server following the above in hardly 3 hours. Go ahead and try by your self.
Hope it helps
Upvotes: 3