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

GPS uses a system of satellites (24 in number) to determine the location of a receiver(Android device). The satellites transmit information to the receiver and receiver use this transmitted information to measure the distance to each satellite by the amount of time it takes to receive a transmitted signal. A minimum of three satellites’ distance from the device is needed to determine a 2-D location. Another thing to note is that the system of satellites keeps revolving around the earth, so the satellite should be in the “line of sight” of the device in order for the device to receive the signals.

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

Network Provider

The network location provider can use different ways to determine your location such as cell towers, or wireless network information.

Wifi

In case of WiFi, the device tracks which access points it can detect and the current signal strength. Based on that information and WiFi’s MAC address, it determines approximate location. Using Wifi has certain advantages over GPS provider. It consumes less power and it works better in areas where GPS signals aren’t very helpful to determine the location. For example, indoors and urban areas where wifi is common but due to density, signals are properly received by the device.

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

Cell IDs

Android can also use cellular network (in a similar way as Wi-Fi access points), to determine the location of the device. This provider works only if the device is connected with a cell tower. The device knows the unique ID of the cell tower and also the IDs of previous towers it was connected to, and based on that, the Google location service determines the location.

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

Passive Location Provider

This provider is quite interesting. Rather than getting location information on its own, the passive location providers get the location update when some other app has requested for it. So it kind of piggy-backs on someone else’s data. Since it depends on other’s data, it doesn’t control the source of the location update, which means, it can either get the data from GPS provider, or from Network provider, or from neither of them(if none of the other apps are receiving location updates). Hence, it is mandatory to have *android.permission.ACCESS_FINE_LOCATION * permission. Since Passive location provider is not guaranteed to receive any location update at all, hence you shouldn’t use it in the app if it is in the foreground. But you can use this provider in the background to keep your app upto date.

Location Provider Permission required Accuracy Power consumption
GPS Provider android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION Most accurate data (Upto 20ft) Highest power consumption
Network Provider android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION Lesser accurate data than GPS (Upto 5300ft / 1mile) Lower battery consumption than GPS
Passive Provider android.permission.ACCESS_FINE_LOCATION N/A N/A

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

Location Settings

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