MapView的apiKey
16lz
2021-01-26
我们在使用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 " );
更多相关文章
- android sp文件一个键值保存多条信息
- 如何给android studio加速(加快gradle build)
- android数据持久化总结
- Android(安卓)Dialog 示例
- 《第一行代码Android》学习总结第十章 Service实践——下载功能
- Android(安卓)3.1 r1 中文API文档 (121) ―― ResourceCursorTre
- android文件命名错误Invalid file name: must contain only [a-z
- 解决Android(安卓)SDK Manager下载太慢问题
- Android定时器和Handler用法实例分析