Geolocation and Google Maps are two important features of most Android devices.
Geolocation is a feature which Android applications can use to obtain the position of the device. Geolocation uses either the GPS, the GSM network or Wifi to determine (with different levels of accuracy) the latitude and longitude of the device. It can also determine the altitude, bearing as well as speed of the device if possible.
In SongExplorerForAll v10, we get the coordinates (latitude and longitude) of the device at regular intervals and display them in a Toast. Essential Android classes used for geolocation here include LocationManager, LocationListener and Location.
An important part of the Android user interface is the notification bar (status bar). It is located at the top of the screen and sometimes at the bottom right for tablets. The notification bar features status icons indicating the status of the device (e.g. battery level, Wifi signal strength etc.) as well as notification icons from applications. Notifications allow you to keep user informed about relevant and timely events in your app.
In SongExplorerForAll v11, when we obtain the device’s coordinates, we create a notification which displays the latitude and longitude. Notifications are created and managed using the NotificationCompat.Builder and NotificationManager classes.
Most of the time, clicking on a particular notification results in an action being performed such as opening a new activity. In SongExplorerForAll v12, when the user clicks on the notification, the position indicated by the coordinates will be displayed on a map. This is done by using the Google Maps API.
To display a map from Google Maps in Android, it is important to use the Google Play Services.
- Ensure that you have installed the Google Play services application on your physical device.
- Make sure that the Google Play services package has been added to your SDK.
- Google Maps requires an API Key to work. Make sure that you enable the Google Maps API and get the appropriate API key.
- Finally, the AndroidManifest of the project as well as the layout need to be modified accordingly.
Once this is done, the idea is to use classes provided by Google to control what is shown by the map.