Obtaining a Maps API Key for Android applications

本文详细介绍如何在应用中使用MapViews,包括获取MD5指纹、注册证书指纹、添加Maps API Key及启用MapView元素的最后步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

If you want to use MapViews in your application, you must obtaining a Maps API Key. Details are listed athttp://code.google.com/android/add-ons/google-apis/mapkey.html. But there is also something confused, so my experience is recorded. The following is about how to use MapViews for Debug, not for release which is similar. Some words are copied from google code directly.

Step 1. Getting the MD5 Fingerprint of the SDK Debug Certificate

To generate an MD5 fingerprint of the debug certificate, first locate the debug keystore. If you are using Eclipse/ADT and are unsure where the debug keystore is located, you can selectWindows >Prefs> Android > Build to check the full path, which you can then paste into a file explorer to locate the directory containing the keystore. In my Win7 system, the path isC:\Users\test\.android\debug.keystore.

Then, in command line console, type the command:

$ keytool -list -alias androiddebugkey \-keystore <path_to_debug_keystore>.keystore \-storepass android -keypass android

Note that keytool command comes with the Java SDK. You should find it in the directory likeC:\Program Files\Java\jdk1.6.0_27\bin. If you haven't set the Environment variables you may need to navigate toC:\Program Files\Java\<"your JDK version">\bin or others in the command prompt. See Figure 1.

Figure 1

Now, you can get the MD5 Fingerprint.

Step 2. Registering the Certificate Fingerprint with the Google Maps Service

Load this page in a browser http://code.google.com/android/maps-api-signup.html. See Figure 2.

To register for a Maps API Key, follow these steps:

  1. If you don't have a Google account, use the link on the page to set one up.
  2. Read the Android Maps API Terms of Service carefully. If you agree to the terms, indicate so using the checkbox on the screen.
  3. Paste the MD5 certificate fingerprint of the certificate that you are registering into the appropriate form field.
  4. Click "Generate API Key"

The server will handle your request, associating the fingerprint with your developer identity and generating a unique Maps API Key, and then will return a results page that gives you your Key string.

Figure 2

Step 3. Adding the Maps API Key to your Application

Once you've registered with the Google Maps service and have obtained a Maps API Key, you must add it to your application's MapView objects, so that the Maps server will allow them to download Maps tiles.

For <MapView> elements declared in XML layout files, add the Maps API Key as the value of a special attribute —android:apiKey. For example:

<com.google.android.maps.MapView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:enabled="true"
 android:clickable="true"
 android:apiKey="example_Maps_ApiKey_String"
 />

For MapView objects instantiated directly from code, pass the Maps API Key string as a parameter in the constructor. For example:

mMapView = new MapView(this, "example_Maps_ApiKey_String");

Step 4. Final Steps to Enable MapView Elements

If you've added the Maps API Key to the MapViews in your application, here are the final steps to enable the MapView elements to run properly:

  • Make sure that you added a <uses-library> element referencing the externalcom.google.android.maps library. The element must be a child of the<application> element in the application's manifest. For example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.package.name">
 ...
 <application android:name="MyApplication" >
   <uses-library android:name="com.google.android.maps" />
 ...
 </application>
  • Sign your application with the certificate that corresponds to the Maps API Key referenced in your MapView elements.

Enjoy it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值