Monday, February 11, 2013

Hi,
Google has introduced the new API for android known as api v2 for Google maps.

Android app on Google Play 

Google is now distributing access to its services in Android powered mobile devices through Google Play services which is installed as an updated in every android powered device.

Browse Android Sample Codes Repository


To use maps using v2 api you need to do bit more work then before using maps in your android apps.

Step - 1

At first you need to create the fingerprints of your debug.keystore.
To locate your android environment debug keystore:

Open Eclipse > Under Window > Go to Preferences


Step - 2


A window will gets open. In window select Android from the left panel and click on build

Android > Build

There you will find the location of your Default debug keystore.




Step -3


Select the location of debug keystore and open the command prompt.





Step - 4


Now in command prompt go to the location of your keystore path.




Step - 5


Now we have to generate the SHA1 fingerprints for our debug keystore.

To create the the fingerprints type the following command:

keytool.exe -list -v -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

And hit enter. 

You will get the SHA1 fingerprints for your keystore.

Now you have SHA1 finger prints of your keystore, which you need to register on Google API console along with your android application package name.

The pre requirement to get you API key for v2 maps is that you must have decided the package name of your application first.


Android app on Google Play 


Google API will provide you api key for maps for your provided SHA1 and package name.

To sign up for Google API go to following link:


On the left most options select "Services






From here you can manage all you Google API Services. To activate Google Maps Android API v2, scroll down the page and ON your service. This service is completely free for Android apps with unlimited number of requests.




Now you have your SHA1 and android application package name with Google Maps v2 service activated.

Next step is to create your API key. For this click on API Access tab from the left menu options.




On this page you will find an option to Create new Android Key. Click on the option to create a key.

As you click you will get a window to enter your SHA1 with application package name.



Enter your SHA1 with application package name as shown below:



As you can see the entered value is your SHA1 followed by application package name separated by semicolon( ; ).

Now click on Create button on the window and you will get your API v2 key for maps.



Now you are almost done for your keys and all. Next step is to create an android project for maps using api v2.

Copy the API key for your android project.


To create an android project using api v2 you need Google play services installed in your SDK. You can download the services as mentioned below.




In Eclipse select Android SDK manager.
From manager window, under extras install "Google Play Services"


Android app on Google Play 



To make a project for maps you need google-play-services lib project imported as a library project in your eclipse.
You can import the project directly from your android SDK samples in eclipse or you can download from link below and import it as android project in eclipse.

https://docs.google.com/file/d/0B5G63uCHzYC-cUJydEFPZnJlb3c/edit?usp=sharing

Open above link; Go to File on above option bar and select download to download the project.



One important thing you need to keep while importing the project is that to make the imported project as a library.




To make imported project as library; just right click on project > Go to Properties > Select Android from left panel > and select Is Library check box


Now after importing the Google maps API library project into eclipse, you can add a Maps project into your eclipse.

Click on the link below to download the maps project and import as android project.

https://docs.google.com/file/d/0B5G63uCHzYC-U1FnWVR0UW1nTnc/edit?usp=sharing


Below is the view of your manifest file for maps project:



You need to add following features and permissions:


<permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


Also you need to add following meta data tag under application tag:


<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyA-Ljypl1fnvSFz4QVf9e2WdQl7cc0BdW0" />



Below is the snippet of main.xml of your project





Android app on Google Play 

Browse Android Sample Codes Repository