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.
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.
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.
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.
GPS need clear sky to connect with satelites and fix a positions. This is now always the case.
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.
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.
More detailed info can be found on http://en.wikipedia.org/wiki/GPS
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?
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: http://developer.android.com/google/play-services/setup.html
keytool -list -v -alias androiddebugkey \ -keystore debug.keystore \ -storepass android -keypass android
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: http://developer.android.com/google/play-services/setup.html