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

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 notificationInterval.

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).

Accuracy

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.

GPS provider data compared to actual location

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.

Accuracy

The following map visualises data recorded for the network provider when walking through Melbourne.

Network provider data compared to actual location

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.

Wrong WiFi Hotspot Location

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.

Conclusion

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.

Code

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.

About Marc Fasel

Marc is a Senior Consultant with Shine Technologies. He has written code in 19 programming languages, but can only speak two natural languages. He enjoys referring to himself in the third person.
This entry was posted in Android, Mobile and tagged , . Bookmark the permalink.

21 Responses to A Good Look at Android Location Data

  1. Get more YouTube subscribers says:

    nice article!

  2. woodly says:

    good article. What device did you use?

    • Marc Fasel says:

      Hi Woodly,

      I used an HTC Desire S for the tests. Hopefully I can follow up on this blog and compare the data to other Android devices to see if there are differences.

      • John Morgans says:

        Mr Fasel I read your article. I am an investigator with the DA office in San Diego CA. I have been having difficulty trying to find someone who can testify to this stuff in a pending robbery case that I have been working on. The defendants phone in question happens to be an HTC Glacier Android 4G. We have downloaded the contents of the phone and it shows the GPS data that appears to be network location provider and not true GPS. I have plotted out what I found in Google Earth and it shows the defendant using his phone immediately before and after one of the robberies and very close to the location. It also helps that this robbery occurred at 0400 hours. I would like to pick your brain on this subject to get a better understanding of what I am looking at and some of the numbers associated with the data. I would also like to know if either you or if you know someone else in the US who could testify for us in this matter. If it would be possible to have you call me I would greatly appreciate it.

      • Marc Fasel says:

        Hi John, please contact me on my Shine email marc.fasel@shinetech.com, and I’ll try to help you with your questions.

        Cheers

        Marc

  3. eekay says:

    Nice article!
    Thanks!

    I’m looking into the possibility to trigger my application when the user is on a specific location (wether the app is running in the background or not). Is that possible too?

    I’d like to show a notification or just run my app..

  4. Prateek Jain says:

    Thank you !! Nice example.

    If the listeners are running always in the background won’t it be affecting the battery life of phone?

    • Marc Fasel says:

      Hi Prateek,

      the listeners – that’s you code – don’t really affect the battery life, it is the location providers running in the background that use the power. The GPS is a real power hog, so and it is recommended not to use more than once every 10 minutes when running in the background. The Network provider is better, but even that should be used sparingly.

  5. kz says:

    Nice article! Thanks

  6. Pradeep VR says:

    Hi Marc thanks for the article, I would like to know how we can get the location using Assisted GPS, it would be highly helpful if you can guide me……..
    Thnx……….

  7. birendra says:

    hi Marc I made an app to track user location . with GPS_PROVIDER its very accurate as u had shown above but when I shifted to NETWORK_PROVIDER accuracy is gone above 1000m my question is how to use WIFI to reduce this accuracy around 200m

  8. Amer says:

    Very good article..Thank you for posting

  9. Pingback: Ideal GPS minimum time and minimum distance setting for fleet management apps | Savaari Blog

  10. sb says:

    Marc doing my final year project on a location orientated android app and comparing the providers is a big part found this by far one of the better reads to date nice work.

  11. Pingback: Bertuztracking urban movements in Android without GPS | Bertuz

  12. Very nice article and example,thank you!

  13. Anthony Isaacson says:

    Excellent article, huge thanks to you for all of this research.

  14. gumuruhsspj says:

    so, again… what are the alternative of gps for indoor?
    i wonder… how could we detect either we’re indoor/ outdoor from the android app
    that has no internet connectivity at all?

  15. sdz says:

    Can you suggest me a code to get the accurate location by comparing the locations from GPS_PROVIDER and NETWORK_PROVIDER.

  16. hi, see this link http://developer.android.com/guide/topics/location/strategies.html
    i’m use method isBetterLocation(Location new,Location current)
    then…
    @Override
    public void onLocationChanged(Location location) {
    // if the new location is better than the previous, so Arrow
    if(isBetterLocation(location, this.location))
    this.location=location;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s