0

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.

ivanhoe_gg
  • 81
  • 1
  • 9
  • 3
    "I've read that there is a limitation on Android to send coordinates through network connection, and this limitation is set to 45 seconds min." -- I have no idea what you are talking about. – CommonsWare Jun 05 '13 at 19:29
  • There is no superficial 45 second limitation, don't know where you read that but if you "learned" other things from that source as well, I'd take them with a grain of salt. – FoamyGuy Jun 05 '13 at 19:31
  • check out my question : http://stackoverflow.com/questions/15747543/locationlistener-of-network-provider-is-enabled-but-onlocationchanged-is-never if @CommonsWare or FoamyGuy could take a look at it, i will be very grateful, because i'm stuck in this for a long time – Guilherme Gregores Jun 05 '13 at 19:34
  • Sorry, I wrote it wrong. What I've read is that there is a time interval limitation on Android to get location through network provider. It isn't truth? I've read it here: http://stackoverflow.com/a/9527556/1861168 and also in some other similar threads. Thanks! – ivanhoe_gg Jun 05 '13 at 19:34
  • I just tested `requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this)` and I am getting readings on average every 20 seconds. – CommonsWare Jun 07 '13 at 19:21
  • @CommonsWare mmm, I will test it again today, maybe it was my fault. Thank you for testing and sharing! – ivanhoe_gg Jun 08 '13 at 12:24
  • Note that I got that on a Galaxy Nexus running 4.2. It's entirely possible the behavior will vary by OS level, possibly even by device. Also, many the readings were *exactly* 20 seconds apart, suggesting that there is a baked-in limit, but the limit will vary. – CommonsWare Jun 08 '13 at 12:33
  • @CommonsWare alright, I'll run some tests this afternoon with a Galaxy S2 4.1.2. and post the results back. 20 seconds would be really enough for my purpose. Once again, thanks! – ivanhoe_gg Jun 08 '13 at 13:45
  • @CommonsWare Mmm, I don't know if I'm doing something wrong, but I'm not even getting new locations. I'm using: locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); where locationListener is just a normal locationListener: locationListener = new LocationListener() { public void onLocationChanged(Location location) { if(location != null){ //I send the coordinates to my server – ivanhoe_gg Jun 08 '13 at 20:16
  • I finally got it working, but using the GPS provider, I don't know hwy, but the network provider is not working as it should on my phone. The onLocationChanged is never called, whereas the listener for the GPS works like a champ. I will use GPS and forget about network, to be honest this is something very irrelevant in my app, so it will be enough. Thank you for all! – ivanhoe_gg Jun 09 '13 at 11:36

1 Answers1

1

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.

Bobbake4
  • 24,509
  • 9
  • 59
  • 94