我们在使用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 " );

更多相关文章

  1. android sp文件一个键值保存多条信息
  2. 如何给android studio加速(加快gradle build)
  3. android数据持久化总结
  4. Android(安卓)Dialog 示例
  5. 《第一行代码Android》学习总结第十章 Service实践——下载功能
  6. Android(安卓)3.1 r1 中文API文档 (121) ―― ResourceCursorTre
  7. android文件命名错误Invalid file name: must contain only [a-z
  8. 解决Android(安卓)SDK Manager下载太慢问题
  9. Android定时器和Handler用法实例分析

随机推荐

  1. Android中的GPS应用开发入门教程
  2. Android基础 : Android(安卓)Service
  3. Handler和Message的使用之三
  4. Android客户端应用享用传统Web服务
  5. 【Android】进入应用和切换界面时闪屏的
  6. Flex学习小心得
  7. 如何安装新版Android(安卓)Studio 3.0
  8. android moudle 资源文件重命名
  9. Android(安卓)Service生命周期及用法
  10. 这个彬彬就是逊啦—才搞懂小学知识求最小