How to construct a Android project with Google Map APIs

1. Setting up a Maps Project Here's how to set the build target, if you are developing on Eclipse with ADT:     * If you want to add Maps to an existing application, right-click the project in Package Explorer, choose Properties > Android and then select a build target from the list displayed. You must choose the "Google APIs" build target.     * If you are creating a new Android project in Eclipse, the New Project Wizard will ask you to specify the build target for the application. You must choose the "Google APIs" build target. 2. Setting up an AVD After you've built your project, you need to be able to run, debug, profile, and test it. To run your Maps-based application in the Android Emulator, you need to set up an Android Virtual Device (AVD) that is configured to use the Google APIs add-on. To set up the AVD, use the Android AVD Manager. Launch the AVD Manager by using the android command without any options. If you are developing in Eclipse/ADT, you can also access the tool from Window > Android SDK and AVD Manager.    1. Click the "New" button to begin creating a new AVD.    2. In the dialog that appears, specify a name for the AVD and select the system p_w_picpath target that you want the AVD to use. Select one of the "Google APIs (Google Inc.)" targets, making sure to choose a version whose API Level matches the android:minSdkVersion attribute in your application's manifest, as described above. 3. Configure the other options and then click "Create AVD". Once you've finished creating the AVD, you can run it from the AVD Manager UI or you can use the emulator's command-line interface. If you are developing in Eclipse, you can configure a Run Configuration to start the AVD and install your application on it. 4. Referencing the Maps Library from the Application's Manifest File To use the classes of the Maps external library in an application, you must reference the library from the application's manifest file. Specifically, you must add a <uses-library> element as a child of the <application> element, with an android:name attribute whose value is com.google.android.maps. Here's an example: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.penguin7.maptest" android:versionCode="1"     android:versionName="1.0">     <application android:icon="@drawable/icon" android:label="@string/app_name">         <activity android:name=".GoogleMapTest" android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>         <uses-library android:name="com.google.android.maps"></uses-library>     </application>     <uses-sdk android:minSdkVersion="3" />     <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest> 4. Getting a Maps API Key MapView objects display Maps tiles downloaded from the Google Maps service. Before you can use Google Maps data, you must register with the Maps service, agreeing to the Terms of Service and supplying an MD5 fingerprint of the certificate(s) that you will use to sign your application. For each registered certificate fingerprint, the service provides you with a Maps API Key — an alphanumeric string that uniquely identifies you and your certificate. You then store your API Key in your MapView objects, so that when they request Maps data, the server can determine that you are registered with the service. If you do not store a valid Maps API Key in your MapView elements, you can still compile and run your application, but your MapView elements won't be able to display data from the Maps server. For this reason, you should register for an API Key as soon as possible, once you begin development. Registering is free and takes only a few minutes. Keep in mind that each Maps API Key is uniquely associated with a specific signing certificate. That means that:     * When you are getting started on developing, you can register using the debug certificate created by the SDK tools.     * When you are ready to publish your application, you need to register again using the certificate with which you will sign your application for release. You must then update your MapView elements so that they reference the release API Key, rather than the debug Key, and then sign your application with your release certificate. Step 1. Use keytool to get MD5 fingerprint change directory to your home, here my home folder is: benjamin, change directory to .android, here you will find a default debug.keystore named as androiddebugkey, input command like this: keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android then you will obtain a private key something as following: androiddebugkey, Dec 13, 2009, PrivateKeyEntry, Certificate fingerprint (MD5): 96:0E:E0:72:E2:E3:F9:20:AC:F6:A7:8F:71:56:BC:7c Step 2. Go to http://code.google.com/android/add-ons/google-apis/maps-api-signup.html To register for a Key, you also need a Google Account. Once you register, your Key will be associated with your Google Account. After you have checked the "I have read and agree with the terms and conditions" checkbox and paste the MD5 into "My certificate's MD5 fingerprint:" edit box, you will get a Maps API Key. Summerized by Benjamin Qi Intern of Beijing PalmCity Science and Technology Co., Ltd MSN: benjaminqi@hotmail.com 2009/12/27 night refer to: Google Projects for Android: Google APIs http://code.google.com/android/add-ons/google-apis/maps-overview.html
相關文章
相關標籤/搜索