LoginSignup
14

More than 5 years have passed since last update.

Google Maps Android V2 APIキーでハマった点

Posted at

Google Maps Android API v2を使用するには、APIキーを取得してAndroidプロジェクトに組込必要があるのですが、そのAPIキー絡みでハマリまくったメモ。

パッケージ名でハマる

Google API Consoleでプロジェクト作成→ Servicesをオン→Create new Android keyでキーストアのSHA1を登録。
[キーストアのSHA1;アプリのパッケージ名]
の形で登録しないといけないのですが、

NGな例:
[キーストアのSHA1;com.example.app.name]

OKな例:
[キーストアのSHA1;com.example.app_name]

ええ、2日ほどハマリましたよ…。

アプリのパッケージ名はドメインを逆にして後ろにアプリ名を付けるのが通例。
アプリ名の中にうっかり.を含めてしまったために実行すると

E/Google Maps Android API(32437): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

パッケージ名を直したらあっさり動きました。
パッケージ名の付け方に関して明確なルールは無いんだろうか…?

Manifest.xmlでハマる

キーストアのSHA1を登録したらManifest.xmlに

Manifest.xml
<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="APIキー" />

のようにAPIキーを埋め込むのですが、上記のエラーのおかげで、あっちこっち触りまくっていたら、meta-dataが複数入ってしまっていて、実行すると

E/Google Maps Android API(32437): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

Manifest.xmlはちゃんと整理しましょう…。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14