Know your sensors — Android Location Services

Location services on handheld devices have transformed this world. Several billion dollar companies like Uber exist because of it. Location services provide contextual information keeping in mind your current location. It could be search results, place recommendations, restaurants near you etc. We call this facility Android Location Services, which consists of different location providers and they have their own strengths and weakness. In this blog, we will assess the types of location providers that are present in Android Location Service and will look at the scenarios when one should be used over other.

GPS

In order to use this provider, we need to add the below permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Limitation

  • GPS location provider relies on a separate radio, it consumes more battery power than other location providers. So if your app remains active for a long time, this can drain your battery.
  • Since your device needs to perform calculations based on the signals received, you need to take care of not blocking the app if calculations take longer(in case where it is difficult to receive signals).

Network Provider

Wifi

In order to use it, you need to add either of the two lines in your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Or

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Limitation

  • Since the provider needs wifi signals to determine the location, the Wi-Fi networks must be in range.
  • Some access points have SSIDs that ends in _nomap so their information will not be sent to the location service.
  • The Google location services determines the location from Wifi by creaking a network map, so if the location of wifi is changed, the service will determine the wrong location unless other connected devices confirm this change.

Cell IDs

In order to use it, you need to add either of the two lines in your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Or

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Limitation

  • The device must be connected to a cell tower.
  • The cell tower must be providing the needed information that is needed to create the network map.

Passive Location Provider

Let compare all the location providers we have learned so far.

Comparison of Location providers

You can also control the ways by which Google location service determines your location. Checkout the below image of location setting:

In the next few articles, I will go through the implementation of these location providers.

If you like it then put a clap (👏 ) on it.

Senior Software Engineer @Joist, Author of Kotlin Programming Cookbook.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store