still under construction, but feel free to explore :)
HOME / Articles/Tutorials / Android Articles/Tutorials / Tutorials on Android programming / Tutorials on Location APIs and Maps / Android Location with Google Maps tutorial

Android Location with Google Maps tutorial

Guide and examples how to use Location API and Google Maps

This artcile is based on Android 4.3 API 18

1. Options to obtain location information

1.1 Using LocationManager

LocationManager is part of the Android Framework Location API. It is the 'old' way of obtaining user location using different Location Providers. To obtain an accurate and consistent location track using this method the developer should wrap it around with lots of logic to choose the best provider and how often to poll or request location updates in order to preserve battery.

1.2 Using LocationClient

LocationClient is part of the Google Location Services API.

1.3 Why Using Both

Fianlly when I say 'old way' i mean that LocationClient can be used for most of the cases for location aware apps, however LocationManager has still some methods wich are not supported in LocationClient. For example location returned by LocationClient doesn't specify its sorce and also it is not possible to check if GPS is avaltable from Google Location Services API.
Another important point is that Location Services API is part of Google Play Services so in order to use it you have to have this installed. Not only that but it has to be the right version. For example if your application is built with google play service lib version 3.2.25, it will not run on version 3.1.36 which is in HTC wildfire 2.3.5 for example.

For internal Android framework information on this topic check

2. Important points when estimating user location

2.1 Different location sources, how to choose which one to use and when

In case of LocationManager user location can be obtained by using GPS, Wifi or Netwrok Cell id so the developer needs to choose which ones to use and how. Determining which to use and trust is a matter of trade-offs in accuracy, speed, and battery-efficiency.

2.2 Wifi and Cell-ID might not give accurate enough data

In many cases Wifi and Cell-ID will provide data with accurace over 100m and some times over 1000m and even bigger (it happens to me once around 140km). In this case this data might not be useful at all on the contrary it might damage all the data analyses.

2.3 GPS might not work in closed spaces or between high buildings or rocks or might give wrong data

GPS need clear sky to connect with satelites and fix a positions. This is now always the case.

2.4 GPS needs time to initialize and might not give immediate location fix when needed

Sometimes when you need alocation information you need it right away and cannot wait. If GPS is not initialized you might wait quite a while to get a location fix from it. So in this case different location sources might be considered.

2.5 GPS might take lots of battery power

GPS consume significantly more power than the other location providers. There are several factors why it is like that:

  • GPS needs to power its antenna
  • GPS prevents the device to sleep
  • GPS is processor-intense (listens and processes information for satellites contantly
  • GPS initial acquisition of the satellite’s navigation message can take lots of time and power.
GPS needs at least 3-4 satellites to communicate to for a location fix. Each satellite continually transmitting messages(specifying their exact location, trajectory, speed, the time each message was sent and the rough location of all the other satellites in the constellation) at 50 bits/sec and the GPS receiver needs to process them. A-GPS(Assisted GPS), which is designed to make the GPS work better in poor reception areas uses also the phone’s radio and (if available) Wi-Fi networks to determine its location and to receive the navigational message from the satellites.
More detailed info can be found on

2.6 Using helper APIs or functions like locationManager.getBestProvider might not be accurate

For example if you have GPS enabled and execute:

	     String theBest = locationManager.getBestProvider(new Criteria(), true);
	     Location loc = locationManager.getLastKnownLocation(theBest);
the best provider returned will be GPS, but if it is not initialized location returned will be null. So isn't it in this case beter to use wifi although with accuracy around 700m?
Another example is when using LocationClient it does not give you info of the Location source it delivers. Also it might happen that new location received will be much lower accuracy compared to the one received just 11 secounds(as set in the FusionEngine SWITCH_ON_FRESHNESS_CLIFF_NS) ago. Having that we are not moving too fast in that case isn't it better just to ignore it?

3. Overview of Android Framework Location API


4. Overview of Google Location Services API


5. Example of using Location APIs

5.1 Prerequsites

5.1.1 Google Play services client library

This is needed in order to use Google Location Services API. Detailed information how to set it up and refference it in your project can found at:







6. Google Map Prerequsites

6.1 Installing SDK


6.1 Obtaining key

for Debug key:
	    keytool -list -v -alias androiddebugkey \
        -keystore debug.keystore \
        -storepass android -keypass android



7. Google Map Overview


8. Google Map example app

8.1 Prerequisites

8.1.1 Google Play services client library

This is needed in order to use Google Maps API for Android, the same one we used for Google Location Services API. Detailed information how to set it up and refference it in your project can found at:

9. Links

Author: DjoDjo