Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發實例

使用 MapView 前必看:如何申請 Google Maps API Key

編輯:Android 開發實例

Google 地圖是它的看家本領之一,能提供精確的位置顯示。Android 對應的元件就是 MapView。不過 MapView 不能拿來就用——它要求你具備一組 apiKey,本質上就是把你的簽章身分綁到使用紀錄上。

以下說明取得這組 key 的完整流程(本文不涵蓋 MapView 本身的用法)。

A. 找出 Debug Keystore 位置

在 Eclipse 中開啟 Android 的 Build 設定:

Windows → Preferences → Android → Build

畫面上會顯示預設 Debug Keystore 的路徑,記下來。

B. 取出 MD5 憑證指紋

開啟命令列視窗,切換到 A 步驟找到的目錄,執行:

keytool -list -keystore debug.keystore

在輸出結果中找到「憑證指紋(MD5)」那一行(英文環境顯示為 Certificate fingerprint),複製這串字元。

C. 到 Google 登記取得 apiKey

前往 Google 地圖 API 的登記頁面,把剛才的 MD5 指紋與你的 Google 帳號送進去:

https://code.google.com/intl/zh-CN/android/maps-api-signup.html

送出後就會取得一組 apiKey。

D. 套用

在版面檔中設定 MapView 的屬性即可:

android:apiKey="你的apiKey"

重點觀念

這套機制的核心是簽章與 key 的綁定:debug 用的 keystore 每個開發機都不同,正式發布時還必須用 your own release keystore 重新申請一組 key,否則使用者裝置上的地圖會顯示空白。這也是為什麼換電腦開發後地圖突然失效的原因——指紋變了。後來 Google 已將這套機制改為整合在 Google APIs Console 中的 API Key 與 SHA-1 憑證指紋管理,流程概念則完全相同。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved