Continuous sending location to server.. good or bad? - android

I am developing one tracking application where a user can track other users location continuously and show it in map.For continuous location updates i am using FusedLocationApi and getting location updates correctly. My question is to send these location to other device, is it a good habit to send these location updates to server continuously? If we make connection request to server so frequently then won't it be draining battery fast? Thanks in Advance. Any help is appreciated.

it is not good actually because it consumes a lot part of battery and also network. But as per your requirement it is good. Even i am also working on almost same concept of application but it is okay coz there are no another solutions so keep moving on that...

Related

Backend and Android technology for fast periodic communication

I'm trying to implement a fast communication between two android phones at a certain moment by, preferably, going through a server (since it's easier to be consistent).
The phones have to communicate their gps locations every x seconds, with x being as low as possible, with only one of the phone having to be on the app, the other can be idle (but obviously not turned off).
The first solution I tried is a syncadapter in the app which updates every x seconds, sends requests to server writing its location in a DB, and then the other retrieves the location in the same DB.
Note : I've implemented it this way only because I already had the underlying architecture (REST API and all) beforehand, but I don't know how to do this in the real world, so feel free to cricize my initial choice and advise me on a better solution
Thank you in advance :) !
You can look at Firebase https://www.firebase.com/ which is a real time database. It does have active listeners in the sdk to get real time updates for your GPS coordinates.
The problem you mentioned can be addressed with
https://github.com/firebase/geofire-java/tree/master/examples/SFVehicles

Background GPS Polling from Web Service

I'd like to know if this is possible on either Android or iPhone:
I would like to have an application run in the background of the phone and send a GPS location to the server every N minutes. As far as I know this is difficult on the iPhone, but can it be done on an Android?
Thinking a bit more on the iPhone - could I create a web service that runs timers for each application and, on timer elapse, push a notification to the phone to start the GPS service and send the location information back to the server? Can I push notifications to an iPhone application in the background?
Thanks!
Re Android: yes, this is also possible, and just as with the iPhone, the less accuracy you need, the faster this will be. It is also asynchronous , so you will need a similar approach. As opposed to the iPhone though, you can start the GPS and wait for location updates in a background service, so that you can send the current location to the server whenever you have it.
Re iPhone: yes, you can push notifications when the app is in the background, but you should know that the location services API is an asynchronous API (having been working on it myself...:)) so you can't time it per se (you can for example "expose" it every N seconds, saving the last location that was provided - so essentially implementing a logic that will make it asynchronous, but with a certain cost to the user experience).
Also note that having location services running in the background is a huge drain of battery. here it really depends on the type of application that you are building. If you dont need high accuracy (say, knowing the city is enough) you could set the accuracy of the API to be large, which wont trigger WiFi and GPS, and will use only cell - less battery drain. If you need really high accuracy (street corner, etc.) this wont be super useful for you.
Adding some more info for your convenience: like I mentioned, accuracy requirement will trigger the different location services, which in return affect batter consumption. In general the accuracy is:
GPS: ~10 meters
WiFi: ~100 meters
Cell: 500 meters (urban canyon environment) to 50Km (in open environment)
Hope that helps.

Best Practice to report user location continuously

I'm designing an application where application in server side need to be continuously aware of user location. I'm thinking to create an Android service that run in the background and continuously query user location and send the result to an application in the backend server. However, I wonder if this is the best approach in terms of battery saving. For example, in iOS, there is something called "Significant-Change" to serve such purpose, does Android have similar thing.
I suggest to create a background Service which just uses the NETWORK_PROVIDER and the PASSIVE_PROVIDER. You can use the minTime and the minDistance parameter to avoid draining the battery. Documentation
And Reto wrote a great post about obtaining users location
http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html
Regarding your comment you have to start your service sticky:
Documentation

Android service location code?

I've been looking everywhere for an example of code that is a Service that update a web server on the users location. this is made almost impossible because of the use of the word 'service' as it is used in the context of location service, for example 'googles location service'. please can anyone point me in the direction of an example where a SERVICE gets the location and does something with it. I can send it to a web service so I'm not asking for that but I just want to know if there is a way of every certain amount of time and distance a service will update the web server?
Look at Android docs about obtaining user location.
You will have to make several decisions:
How accurate do you need your updates to be?
How often do you need them?
This greatly affects device's power consumption. Personally I loathe the apps that prevent full sleep and have GPS constantly turned on - this drains the battery in a couple of hours.
I highly recommend you look at this blog post: A Deep Dive Into Location. There is a link to a great example app.

Where to initialize GPS to stay on for longer than the activities

I am writing an application that has to send to the server its GPS location every X seconds, and I was wondering if the right place to have this running was inside the Application Class since it has to keep sending messages even if you change activities.
Right now I initialized inside the activity and then have a different thread with a timer send the latest location to the backend.
Am I correct? I ask mainly because I have had complains that the GPS sometimes gets stuck, but when they launch another application with a GPS it starts working again in my program.
[EDIT: the application is for a company that will be using the app alone in a Galaxy Tab]
Thanks
A simple way: Create a Service and register it to listen to LocationManager updates. If you want to send data even when phone goes to sleep then take a look at WAKE LOCK.
However this will use GPS and network and will drain battery. People don't like such apps - I know I wouldn't use it.
To make things more user-friendly:
Use passive location provider. This leeches location data when other apps use Gps. Use Gps directly only when you dont get data for a longer period.
Cache location data. Register with sync manager to update data when other app also update data. Use DownloadManager to upload data files: DM is smart, it automatically retries on error, even if device is restarted. If files are big, then set it to only upload over wifi.
I highly recommend watching Reto Meier's Android Protips video http://www.youtube.com/watch?v=twmuBbC_oB8

Categories

Resources