In this article, we will create an Android application which draws polyline and markers along the tapped positions in Google Map Android API V2. Long click the Google Map to clear all the existing polylines and markers in the Google Map.
This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.1.0 ) and Android SDK ( 21.1.0 ) and is tested in a real Android Phone with Android ( 2.3.6 ).
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.
Note : Please ensure that, the latest version of Google Play Service Library is installed
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.
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 “
Update the layout file res/layout/activity_main.xml
Update the file src/in//locationmarkerlatlng/MainActivity.java
Update the file AndroidManifest.xml
Note : Replace “YOUR_API_KEY” at line 44 with the api key obtained in step 8.
Screenshot of the application
Download Source Code