现在的位置: 首页 > 综合 > 正文

MapView的apiKey

2013年12月01日 ⁄ 综合 ⁄ 共 2025字 ⁄ 字号 评论关闭

我们在使用Google的地图API进行程序开发时,往往会使用com.google.android.maps.MapView。而使用com.google.android.maps.MapView又需要一个android:apiKey。本文将介绍如何申请和使用MapView的apiKey
一、找到debug.keystore
打开Eclipse--->Windows--->Preferences--->Android--->Build 
查看默认的debug.keystore位置,我的是C:/Documents
and Settings/Administrator/.android/debug.keystore
如果debug.keystore已经过期,请删除它,然后在Eclipse中编译一个Android工程,这时Eclipse将生产一个新的debug.keystore
二、取得keystore的MD5
在命令行,运行命令:keytool -list -alias androiddebugkey -keystore
"
C:/Documents and Settings/Administrator/.android/debug.keystore" -storepass android -keypass android
结果显示:
androiddebugkey, Sep 28, 2011, PrivateKeyEntry,
Certificate fingerprint (MD5): DF:59:A3:47:11:0A:DD:8F:0D:43:2A:06:5D:13:E8:98
这里DF:59:A3:47:11:0A:DD:8F:0D:43:2A:06:5D:13:E8:98就是我们所需要的MD5
:keytool位于JAVA_HOME\bin目录下。
三、用MD5获得apiKey
打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html
  输入上面获得的MD5,填写自己的邮箱,然后会进入这样的一页:
Your key is:
00eTdGt9OWBDzzT0wQBPGYOnaS7pnd6dBj1bJjQ
This key is good for all apps signed with your certificate whose fingerprint is:
DF:59:A3:47:11:0A:DD:8F:0D:43:2A:06:5D:13:E8:98
Here is an example xml layout to get you started on your way to mapping glory:
              <com.google.android.maps.MapView
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="00eTdGt9OWBDzzT0wQBPGYOnaS7pnd6dBj1bJjQ"
                 />
DF:59:A3:47:11:0A:DD:8F:0D:43:2A:06:5D:13:E8:98就是我们需要的MapView的apiKey.
注意:apiKey和你的证书是一一对应。这里的话,它其实是和debug.keystore中的这名叫androiddebugkey的公钥\私钥是一一对应的。
四、使用apiKey
可以在布局文件中或代码中使用apiKey.
示例1
mapview.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:apiKey="00eTdGt9OWBDzzT0wQBPGYOnaS7pnd6dBj1bJjQ"
                android:clickable="true"
                android:focusable="true"
                />
</LinearLayout>
示例2:
 mMapView = new MapView(this, "00eTdGt9OWBDzzT0wQBPGYOnaS7pnd6dBj1bJjQ");

抱歉!评论已关闭.