androidgpslocationmanagerlocation-provider

A-GPS, resetting GPS and sendExtraCommand


I am after a pointer to some information explaining all this. I have a GPS utilising app (being tested on a couple of old HTC Desire phones and a Google Nexus 7), and I notice that - in common with some other apps - GPS location updates can get 'sluggish'. What seems to happen is that the updates (1/sec - this app needs good up to date information) come through OK, but often the lat/long values do not change (when moving around). Interestingly, alt usually does.

After some reading of Stack Overflow, I find 'resetting GPS' with the following code (using permission android.permission.ACCESS_LOCATION_EXTRA_COMMANDS):

Bundle  extras = new Bundle();

extras.putBoolean("all", true);
locManager.sendExtraCommand("gps", "delete_aiding_data", extras);

seems to help: there's an initial hiatus in locations, then true updates seem to come through a lot more usefully - until it happens again.

I also read that the following code

Bundle bundle = new Bundle();

locManager.sendExtraCommand("gps", "force_xtra_injection", bundle);
locManager.sendExtraCommand("gps", "force_time_injection", bundle);

may be used to update the A-GPS cached information to get a faster lock (for a short time), but needs a network connection to perform a download. I haven't tried this yet.

The problem I have is that I cannot find anywhere good detailed information on what these commands are, what they do, when they should and should not be used, why it all happens at all etc. There is some, but it is all a bit anecdotal.

What I am really after is being pointed to somewhere that I can read about the background to it all. I would be perfectly happy if it look slightly longer to lock, providing it didn't degrade over time.


Solution

  • force_xtra_injection causes the gps software to go ask the Xtra server for assistance information. Xtra is a proprietary protocol supported by a specific vendor. It isn't really described in detail that I know about, but I suppose it really includes ephemeris data for satellites.

    force_time_injection forces time assistance into gps software. The time must be in GPS format. This is done by using NTP to determine a reasonably accurate value for GPS time and give that to gps software in your phone to use as assistance in establishing the initial position. Time assistance is only used for the first calculated position. After the first position, the GPS receiver knows time to much greater accuracy than you could ever provide from an external software interface.

    Ephemeris is an orbit model for each satellite. It uses a complicated formula to specify where a satellite is in space if you give it time. Satellites move at ~3.8 Kilometers/second through their orbits, so it's really important to specify time as accurately as possible.

    Time assistance isnt' really used to calculate a position, it is used to determine (along with ephemeris or almanac) what satellites are in view at your location (or the last known location) and what the approximate doppler value for that satellite would be. This allows the GPS receiver to narrow the search parameters and have a better chance of finding satellites at low signal strength and finding satellites faster than without time.

    If lat/long values are not changing, it is because of several reasons:

    1) The position is not really a GPS position, it is based on WiFi data, cellID data, or other source. You can look at the position uncertainty to have a clue as to which source is used. If the uncertainty is hundreds or thousands of meters, it is based on cell ID. If the first position pops out very fast and you have terrible signal conditions (you are inside where signals are blocked, but still get 20 or 30 meter accuracy) then you are probably using WiFi positioning.

    2) The GPS software is clamping position reports. This is something that most people prefer to improve the user experience. Nobody wants to sit at a traffic light and see their GPS position wander around when they aren't driving. If clamping, you can start moving and the clamp should release and start tracking your position after a short time.

    3) You have really bad signal conditions and GPS positions are updating but happen very slowly.

    The best way to get good positions from GPS is to be in good signal conditions and be connected to the internet so you can get assistance data (ephemeris, position, and current GPS time) from some server.