I'm developing an app that tracks the movement of public transport (buses and trams). I'm doing both, client and server side. The client requests the position of a bus from a server database and the server side is just a simple app that should send the current location to this server database every, lets say, 10 seconds for example.
Don't think about performance nor batery life, it doesn't matter. The important app is the one at the client side, the server side is just a simulation as how it should be in case we had real gps installed in every vehicle. So forget about batery life on server side.
I've read that there is a time interval limitation on Android to get location through network provider, and this limitation is set to 45 seconds min. Is it possible to skip this limitation in any way? Would it be better to use the phone GPS to achieve this task?
Regarding the database, I just store an ID (autoincrement) as primary key, latitude, longitude, and a timestamp.
I thought also about listening changes on location, and when there is a change, add a new entry to my database. If I want to check the position from the client side, I will look for the last entry with a timestamp equal or less than the current one. But if the limitation is set to 45 seconds, this approach won't help me either.
Thanks in advance.
You should be using the new "Fused Location Provider" from the recently added location services API in Google Play Services. There is a good walk through on how to accomplish this here. The nice thing about the new location API is you don't have to decide on GPS or Network. The internals of the API will determine which provider should be used to give you the most accurate location. Also, I've never heard anything about a limit to location updates. I'm pretty sure you can get them as fast as 1 update per second, don't quote me on that though.
Related
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
Im trying to develop an Android messenger application where a message is sent by user 1 to everyone using the app, the message contains the GPS location of user 1. Is it possible to determine the distance between user 1 and the user 2 and based on that either choose to display or discard the message. How do I go about it? Cloud you point out considerations that I might have missed out?
Another method I believe is possible is to periodically update a server with every users GPS location and then let the server decide who gets the message, but I would not like to use this method as it would be a privacy issue. No one would want their whereabouts being tracked by a server all day. Is there another solution to this?
You can use the haversine formula to determine the distance between two locations. Here is a link that provides the formula in various languages.
http://www.movable-type.co.uk/scripts/latlong.html
One way of doing this is to store the most recent location of a phone on the server in the database. You can then query the database (using a stored procedure) to determine who your closest neighbors (phones) are by setting a radius. For instance, show me all the phones within 500 meters.
Here is an example of how to do this:
http://www.movable-type.co.uk/scripts/latlong-db.html
We are working on an app with the following requirements:
Users will have a Friends list (small subset of users)
User will need to know when a 'Friend' is close to them (aprox < 1 mile)
We are currently doing the following:
Each User posts there location to a central DB every 15 mins
User searches DB for Users that are friends & distance < 1 mile
The issue is - thats alot of Location Polling & many users don't like constant polling.
Is there a better way?
The current approach looks perfect here.
Other wise you need to manually trigger user that he/she needs to update their current location.
What you can do if some one wants to know near by friends list:
Make a web service call that user from X group is trigger an event for location updates.
Send a push notification to all other user from group X that update current location / sync current location with online database.
Filter users from latest current location details.
Pros:
You will get real time location updates (fraction of mins)
Only limited users (group of users) needs to update their location
Do not need to constantly location polling
Cons:
Push notification required
User have to manually sync their location, if some one does not sync it will be not effective.
However there are many things which needs to be consider for scenario above, I have roughy listed which strikes in a mind first.
Again it still depends on application architecture and server configuration to manage every alternatives.
"User searches DB for Users that are friends & distance < 1 mile"
Maybe it will be better to server side make that job?
The clients only ask server - 'Any friends around me?'
Also you can try to deliver that info by push notifications. But notification can arrive with delay (or may not delivered at all).
I'm not sure about Android but for iOS you can configure your app to update location more conservatively using significant-change location as referred to in the Apple's Docs. Then when your user is actively using the app (or some other business logic such as close to an active friend) temporarily change to the standard location service for greater accuracy and more frequent polling.
By using the significant change method you could just update the server occasionally rather than every 15 minutes and sometimes more frequently if a person is on the move and then alter your search predicate to reflect these update changes.
The part that seemed most relevant was:
The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.
I am developing an app which can record user's location througout the day so app can find out the approx lifestyle of user. app has to collect data in the background at some interval so i need a best strategy to invoke a location update request to LocationManager of android. But it must be optimized in terms of battery and balanced in terms of accuracy.
Right now the flow in my mind is,
iterate through the location providers, give higher priority to NETWORK (as it consumes less power), o this for each,
get the last known location
get the current loction
chek if current is better than last
if yes make this the best estimate, otherwise get location from other provider
i know two parameters which can decide when to invoke location update request,
minimum interval
minimum distance
first i would give them some default value but these must be updated later by using the location history of user and considering other factors in mind like
reduce the frequency of update request if battery is < 75% and further reduce it when
battery is < 50%
increase frequency of update request when user is moving fast (Activity Recognition Class
from google location services can help here)
if we predict the time windows in which user does not move (from history), decrease the
frquency of location updates
use GPS minimal time because it consumes more battery
So these are the pieces that came to my mind but it looks like a mess right now because it is not well structured. So if somebody can help me to add something more in this or can suggest some better strategy (battery must be optimized) i would be very thankful and it was long so please control your emotions if you think i have wasted your time. Thanks
In order to get a good accuracy, Google provides an algorithm that provides, in my opinion, good results. You can find it there : reference
GPS take so time to have a fix, I would say about a minutes (depends on the device).
I would suggest you to look at the Passive Mode, which allows you to receive position without making a fix by using other applications requests.
passive: A special location provider for receiving locations without actually initiating a location fix. This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. Requires the permission android.permission.ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.
gps tutorial
Hope it helps !
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.