In this article, we will create an Android application which will display current location in Google Maps using Google Maps Android API V2.
Since the Google Map is displayed using SupportMapFragment, this application can run in Android API Level 8 or above.
In order to use MapFragment for Google Maps, we need Android device with API level 12 or above.
This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 ). This application is tested in a real Android Phone with Android ( 2.3.6 ).
An alternative method for this application is available at Showing current location using OnMyLocationChangeListener in Google Map Android API V2
1. Download and configure Google Play Services Library in Eclipse
Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.
Please follow the given below link to setup Google Play Service library in Eclipse.
2. Create a new Android Application Project namely “LocationInGoogleMapV2″
3. Configure Android Application Project
4. Design Application Launcher Icon
5. Create a blank activity
6. Enter Main Activity Details
7. Link to Google Play Service Library
8. Get the API key for Google Maps Android API v2
We need to get an API key from Google to use Google Maps in Android application. Please follow the given below link to get the API key for Google Maps Android API v2.
9. Add Android Support library to this project
By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :
- Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
- Right click this project
- Then from popup window, Click “Android Tools -> Add Support Library “
10. Update the file res/values/strings.xml
11. Update the file AndroidManfiest.xml
Note : In the above code, replace “YOUR_API_KEY” with the api key, you generated in step 8.
12. Update the layout file to display Google Map using SupportMapFragment
13. Update the file src/in/wptrafficanalyzer/locationingooglemapv2/MainActivity.java
14. Enable GPS in the device from Settings
15. Running the application
16. Download Source Code
We can tryout this application from Google Play Store at https://play.google.com/store/apps/developer?id=Back+To+Hell