Date Created: Sun 15-May-2011

Related Document Categories:


    Creating a Google Maps key for your development version of Android application


    1. Ensure path to JDK is available to your Android SDK promot

    Set winwdows path to include something like:
    C:\Java\jdk1.6.0_23\bin

    If you can run Javac then you have correctly defined the path

    2. Run Keytool to generate key using this command:

    keytool -list -alias androiddebugkey -keystore "C:/Users/Steve Robinson/.android/debug.keystore" -storepass android -keypass android

    Replace the "C:/Users/Steve Robinson/.android/debug.keystore" with your SDK default keystore path

    Tip use Windows > Preferences in Eclipse IDE and navigate to Android > Build an look for the Default debug keystore value, this will tell you where your debug keystore is located



    Result:



    When you are ready to register for a Maps API Key, load this page in a browser:

    http://code.google. com/android/maps-api-signup.html

    To register for a Maps API Key, follow these steps:
    1. If you don't have a Google account, use the link on the page to set one up.
    2. Read the Android Maps API Terms of Service carefully. If you agree to the terms, indicate so using the checkbox on the screen.
    3. Paste the MD5 certificate fingerprint of the certificate that you are registering into the appropriate form field.
    4. Click "Generate API Key"

    The server will handle your request, associating the fingerprint with your developer identity and generating a unique Maps API Key, and then will return a results page that gives you your Key string.

    To use the Maps API Key string, copy and paste it into your code as described in the next section.

    Note: If you happen to forget your Maps API Key, you can generate a fingerprint for your certificate and register it again. The registration server will give you the same Maps API Key for the specified certificate fingerprint.

    Adding the Maps API Key to your Application

    Once you've registered with the Google Maps service and have obtained a Maps API Key, you must add it to your application's MapView objects, so that the Maps server will allow them to download Maps tiles.


    Now that you have the api key, you can use it in the main.xml layout file of your MapTest application. Here's what mine looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0pJMwVuoj7WB_vP4PXRYCz8uEjt03uaDLpw5MAw"
    />

    </RelativeLayout>

    Note: For MapView objects instantiated directly from code, pass the Maps API Key string as a parameter in the constructor. For example:

    mMapView = new MapView(this, "example_Maps_ApiKey_String");


    Final Steps to Enable MapView Elements

    If you've added the Maps API Key to the MapViews in your application, here are the final steps to enable the MapView elements to run properly:

    • Make sure that you added a <uses-library> element referencing the external com.google.android.maps library. The element must be a child of the <application> element in the application's manifest. For example:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.package.name">
    ...
    <application android:name="MyApplication" >
    <uses-library android:name="com.google.android.maps" />
    ...
    </application>
    • Sign your application with the certificate that corresponds to the Maps API Key referenced in your MapView elements.
    Eclipse Users

    If you are developing in Eclipse/ADT (and have set up Keytool as described above), signing in debug mode is enabled by default. When you run or debug your application, ADT signs the .apk with the debug certificate, runs zipalign on the package, then installs it on the selected emulator or connected device. No specific action on your part is needed, provided ADT has access to Keytool.

    References:
    http://remwebdevelopment.com/dev/a35/Android-How-To-Set-Up-an-API-Key-for-Google-Maps.html
    http://code.google.com/android/add-ons/google-apis/mapkey.html#overview




Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories