申请Google Map API Key

来源:互联网 发布:打印数组 编辑:程序博客网 时间:2024/05/21 06:40

开发Android应用程序,如果使用到GoogleMaps,须先向Google申请一组经过验证的Android Maps API Key,这组Key可以在多个应用程序中使用。


1,申请Android Maps API Key前,需先从开发环境中取得keystore的MD5编码,然后通过Google网站的签署,便可获得

debug.keystore文件路径可由Eclipse IDE中“Window - Preferences - Android - Build”中找到

$keytool -list -alias androiddebugkey -keystore /home/cat/.android/debug.keystore -storepass android -keypass android
androiddebugkey, 2012-9-1, PrivateKeyEntry, 
认证指纹 (MD5): 97:33:40:5E:FD:XX:XX:XX:YY:YY:YY:ZZ:ZZ:ZZ:19:11

Keytool OptionDescription-listPrint an MD5 fingerprint of a certificate.-keystore <keystore-name>.keystoreThe name of the keystore containing the target key.-storepass <password>

A password for the keystore.

As a security precaution, do not include this option in your command line unless you are working at a secure computer. If not supplied, Keytool prompts you to enter the password. In this way, your password is not stored in your shell history.

-alias <alias_name>The alias for the key for which to generate the MD5 certificate fingerprint.-keypass <password>

The password for the key.

As a security precaution, do not include this option in your command line unless you are working at a secure computer. If not supplied, Keytool prompts you to enter the password. In this way, your password is not stored in your shell history.


如果下次需要再查看这个MD5值,可以通过$ keytool -list -keystore /home/cat/.android/debug.keystore命令,输入keystore密码:android得到

Keystore 类型: JKS
Keystore 提供者: SUN


您的 keystore 包含 1 输入


androiddebugkey, 2012-9-1, PrivateKeyEntry, 
认证指纹 (MD5): 97:33:40:5E:FD:XX:XX:XX:YY:YY:YY:ZZ:ZZ:ZZ:19:11


2,访问https://developers.google.com/android/maps-api-signup?hl=zh-CN,输入取得的MD5编码,申请Android Maps API Key

 <com.google.android.maps.MapView                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:apiKey="0mP5XXn2YY7wzy_2ZZc4OObP_WCQQX9hPPpLMMQ"                 />


3,将获得的Android Maps API Key放入工程的layout文件中使用

    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/linearLayout2"
        android:apiKey="0mP5XXn2YY7wzy_2ZZc4OObP_WCQQX9hPPpLMMQ"
        android:clickable="true"
        android:enabled="true" >
    </com.google.android.maps.MapView>