14 Oct 2011 A Good Look at Android Location Data
Getting started with the development of location-based services on Android is relatively easy thanks to the well documented location API. However, getting more serious shows there is still much uncharted territory. One such area concerns the accuracy of real-life location data, which I have recently taken a close look at. In short, location data can be far more accurate than Google’s conservative estimates – at least with the phone that I used.
The Android developer documentation gives estimates on expected accuracy of the location data. This estimate varies according to the location provider used. Android distinguishes two location provider types with the following accuracy:
- Fine-grained location provider like the GPS provider with an accuracy of less than 100 m.
- Coarse-grained location provider like the network location provider with an accuracy of 100 – 500 m
One look at the Google Maps application makes it clear that the estimates for the accuracy are very conservative: in many cases the user location is shown on Google Maps with an accuracy of a few meters, much better than the estimates stated above.
My interest is in the individual accuracy of real-world data rather than an average accuracy estimate. Each time a location provider sends a location update, the accuracy of this individual location is given as well. In this article I look at this accuracy as reported by the location provider, and compare the location accuracy of the two main location providers to actual locations.
Location providers are the sources of location data in Android. Even though the Android API specifies location providers in a very generic way, in practice there are two main location providers: The GPS location provider and the network location provider. Because they use different ways to obtain location data they differ in accuracy, minimum notification interval, time to first fix (TTFF), and battery consumption.
The way you receive location information in Android is to register a Location Listener with the Location Manager. At registration the location provider, notification interval and notification distance have to be specified:
locationManager.requestLocationUpdates(provider, notificationInterval, notificationDistance, locationListener);
The Location Manager will call the
onLocationChanged() method of the listener if the distance since the last location update for the registered location provider is greater then the
notificationDistance, or the time since last location update is greater than the
GPS Location Provider
The most obvious location provider is the GPS. GPS provides data with high accuracy: Less than 100 m is the official number, but real accuracy is often around 2 m – 20 m. Once it is connected to satellites it can provide location updates in intervals as short as a few seconds.
Sounds like an ideal location provider, but the GPS also has its draw-backs. For one, the initial connection to the satellites – Time to First Fix (TTFF) – can be quite slow. GPS traditionally needs to connect to at least three satellites for a 2D location, and initial transmission of so-called Ephemeris data takes a minimum of 30 seconds for a satellite. Once the Ephemeris data has been transmitted and connection to the satellite is made, location updates are very fast.
To speed up the TTFF, manufacturers have come up with a new way to deliver the initial Ephemeris data to the GPS: They use an Internet connection to deliver the data much faster than the transmission from the satellite. Android uses this so-called Assisted GPS (A-GPS) to speed up TTFF to 5-15 seconds, but only if you have an Internet connection.
Another draw-back of the GPS provider is that the battery consumption is quite high, and continued use of the the GPS will drain the battery. Even though GPS location updates can be received every few seconds, the Android developers guide recommends update intervals for the GPS of greater than 10 minutes. This limits the type of applications that can benefit from using the GPS.
Last but not least: Since GPS uses a radio signal, solid objects – especially those made from metal – will obstruct the signal. In practice, this means the GPS will not work in most buildings (GPS is not affected by clouds, rain, or snow, though).
Each location update from a location provider comes with the accuracy of the data in meters. This accuracy is given for each location update. To visualise the location data and the accuracy for each location I wrote an Android application that records the location data in a database. Drawing the recorded data on a Google Map helps visualise the data. The following map shows the data recorded for the GPS provider during a walk through Melbourne.
The black line is the actual path I took during the walk. The white dots are the locations recorded by the GPS provider, while the red circles around the dots indicate the accuracy per location as reported by the GPS provider.
As expected the accuracy of the GPS provider is quite good: Most of the time the accuracy is within 30 m, some times as good as 2 m. That is much better than the conservative estimate of less than 100 m stated in the documentation.
An interesting observation is that sometimes the actual location is not within the circle of accuracy given by the GPS provider. The location marked with 1 on the map is about 25 m off the actual location, with an accuracy radius of about 5 m. Even with the radius of accuracy the result is still 20 m off the actual location.
Another observation that shows the draw-back of the GPS: if we are indoors or have otherwise bad reception there may not be a GPS signal, which means the location is completely lost. Marker 2 shows a section of the walk without any GPS signal. First I walked through a building from the Flight Centre to the cafe “The Journal”. Even after I passed though this building and walked down down the narrow Flinders Lane the GPS reception didn’t improve, so there are no readings at all during this time.
Network Location Provider
The network location provider uses both WiFi hotspots and cell towers known to the Android device to approximate a location of a user. When the location provider is polled, the IDs of the WiFi hotspots and cell towers in the area are sent via Internet to the Google Location Server, a database with location information on WiFi hotspots and cell towers. Google Location Server returns an approximate location of the user.
The data comes from a combination of cell and WiFi hotspot information, and can only be obtained when the device can access the Internet to query the Google Location Server. Accuracy of the data is specified somewhere between 100 m – 1000 m depending on the information available. WiFi hotspots allow an accuracy of 100 m – 500 m, while cell towers only allow for an accuracy greater 500 m. This means the network provider will be very inaccurate in areas without WiFi hotspots. Conversely, the more hotspots and cell towers are in the area the greater the accuracy.
The network provider can give first location results within seconds. This is much faster than the GPS location provider, which even using A-GPS may take up to a minute to give back first results.
The following map visualises data recorded for the network provider when walking through Melbourne.
The black line again is the actual path taken, while the white dots are the locations recorded by the network provider. The turquoise circles indicate the accuracy reported by the network provider. The walk took about 30 minutes, during that time 16 points where within a reasonable accuracy (I discarded those points with an accuracy of greater than 100 m as too inaccurate, just to make the map clearer).
The map shows that at least in an urban area the network provider gives enough data with an accuracy of less than 100 m. Most of them were actually in the area of 50 m. This is not as good as the GPS, but still quite impressive. The network provider also has number of advantages over the GPS: It works both indoors and outdoors, starts up quickly, and doesn’t drain the battery.
WiFi Hotspot Location Data
During recording of the data I stumbled across an interesting anomaly: The network location provider put me in a totally different location than where I actually was. Curiously this happened every time I connected to my WiFi hotspot at home.
The location marked with 1 is near my home, while the location marked with 2 is the place where I used to live. Once I arrived home the network provider placed me in location 2 instead of near location 1. Apparently Google thought I was in my old home once I logged into my home network, because it had previously registered the location of my WiFi hotspot in location 2.
This made me think about how Google actually obtains the location of a WiFi hotspot. It used to be possible to register the location of your WiFi hotspot with Google by hand. This option apparently does not exist anymore. As this discussion shows, the data for the network provider actually comes from data Android GPS providers sent to the Google Location Server at some other time:
“[…] before the GPS acquires a “fix”, Android will send the Wifi’s MAC/SSID and Cell Tower base stations CID/LAC around you to Google’s server and Google’s server will send back your location information; after the GPS acquires a “fix”, your device will send the Wifi MAC/SSID, Cell Tower CID/LAC, and your GPS location to Google’s server and Google’s server will collect this information to refine their own Wifi database.”
The discussion also shows an Email reply from a Google employee stating that updating location information on WiFi hotspots is done automatically when a GPS provider sends new location data, but “may require a significant amount of data from you and other users before changes are made to Google’s location database”. That explains why my WiFi hotspot is still registered at my old home in the Google Location Server.
Comparing the location data received from the location providers with the actual location data shows that both location providers are much better in accuracy than the conservative estimates of the documentation.
For the hightest accuracy the GPS provider needs to be used, but is not suitable for all situations. The limitation of GPS to outdoor use is quite constraining, as is the battery consumption and TTFF, especially when used without A-GPS.
The results of network provider for me came as a surprise: It is quite accurate while doing without the draw-backs of GPS like power-consumption, TTFF, and restriction to outdoor use. It does lead to large inaccuracies in areas without WiFi hotspots.
Clearly a combination of both provides will yield the best results. How they are mixed depends on the application. A foreground application with emphasis on accuracy would use the GPS provider as the primary provider, with the network provider as a backup, while a background application with emphasis on low power consumption would use the network provider as its primary location provider with the GPS as a backup. Varying the update intervals allows fine-tuning the providers to a specific application.
If you want to have a look at the location data on your Android device I have uploaded the code to GitHub. It consists of an Android application that records the data as well as an HTML page that displays the data on Google Maps.