申请google android map api key

简介:

申请google android map api key

网上找到的老外的一篇申请android map api key的文章。原文连接在这里

 文章内容如下:

The Maps API Key


 

The MapView class in the Maps external library lets you integrate Google Maps into your application. BecauseMapView gives you access to Google Maps data, you must register with the Google Maps service before your implementation of MapView will be able to obtain map data.

 

Obtaining and Using a Maps API Key

Registering and using a Maps API Key is free and has two parts:

  1. First you register the MD5 fingerprint of the certificate that will be used to sign your application. The Maps registration service then provides a Maps API Key that is associated with your application's signer certificate.

  2. Then you add a reference to this Maps API Key in each MapView. You can use the same Maps API Key for any MapView in any Android application, provided that the application is signed with the certificate whose fingerprint you registered with the service.

We now outline how to implement these two steps; for more details, see Obtaining a Maps API Key.


To keep things simple we shall register using the debug certificate associated with our development machine to obtain a temporary Maps API key. This is adequate for demonstration and development. However, when you publish an app (e.g., deployment through the Android Market) you must digitally sign it and (if you employ Google Maps) before you publish your application you must register for a new Key based on your release certificate, and update the references in your MapViews to this new key.

 

Getting the MD5 Fingerprint of the Debug Certificate

To generate an MD5 fingerprint of the SDK debug certificate, we must first locate the debug keystore. This will depend on the platform in use. For example, some standard locations are

  • Windows Vista: C:\Users\ \.android\debug.keystore

  • Windows XP: C:\Documents and Settings\ \.android\debug.keystore

  • Linux and Mac OS X: ~/.android/debug.keystore

If in doubt, you can locate the debug keystore by using Eclipse and choosing Window > Preferences > Android > Build.

Once you have located the keystore, the following command issued at a shell prompt will return the MD5 fingerprint of the debug certificate:


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

For example, on one of my Linux systems (named M33) I obtained


[guidry@m33 ~]$ keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android
androiddebugkey, Jan 26, 2011, PrivateKeyEntry,
Certificate fingerprint (MD5): 3C:8D:BD:C1:7F:40:10:82:C9:6B:B1:E2:68:0C:30:13
[guidry@m33 ~]$

Copy the MD5 fingerprint, as we shall use it shortly to register with the Map service. Now use a browser to go to the sign-up page. To register for a Maps API Key,

  1. You must have a (free) Google account to use the Maps service. If you don't have one already, use the link on the page to sign up for one.

  2. Agree to the terms of service by clicking the checkbox.

  3. Paste into the appropriate form field the MD5 certificate fingerprint that you generated above for the certificate that you are registering.

  4. Click "Generate API Key".

The server will return a page similar to the following figure containing your key string.



Keep the key string in a safe place because you will need it for any mapping application that you write. In the next section we will describe how to use this key.

 

Using the Maps API Key

You must add the Maps API key obtained above to any MapView objects in your application, so that the Maps server will allow them to download map tiles. For Mapviews declared in XML files, the key is added as the value of a special android:apiKey attribute. For example, the Maps API key returned when the MD5 key for M33 obtained above was registered is


07WVUg-srWUZbNUe1L0F3PYs0gcOKG-UqXR-DZQ

Thus a MapView on the machine M33 can be registered to receive map data in an application running under the debug certificate by inserting


<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="07WVUg-srWUZbNUe1L0F3PYs0gcOKG-UqXR-DZQ" />

in the XML layout file for the MapView.


This maps API key is valid only under the debug certificate on a specific machine (M33 in this example), for as long as that debug certificate is valid.
  • If I transfer the application to another machine, I will have to obtain a map key for that machine in the same way as described above and change the android:apiKeyattribute accordingly.

  • Even on a given machine, the debug certificate expires after a year and you must delete it to force acquisition of a new one (see the General heading under Eclipse Tips). If you acquire a new debug certificate, your mapping applications will not be able to obtain data when deployed using the debug certificate until you obtain a new maps API key.

  • Also, each MapView within an application must have its own android:apiKeyspecification (but you can use the same API key for all).
The reason that all of this seems more involved than it needs to be is basically that Google Maps are compatible with the Android API, but they are licensed separately from Android.

If you instantiate MapView objects directly from code rather than laying out with XML, the Maps API Key string is passed as a parameter in the constructor. For example, assuming the same API key as above,


myMapView = new MapView(this, "07WVUg-srWUZbNUe1L0F3PYs0gcOKG-UqXR-DZQ");

would register myMapView to receive mapping data.

 

Modifications of the Manifest File

Finally, for your application to use the Maps API key you must declare in the AndroidManifest.xml file that it requires permission to access the internet and that it uses the Google maps library. The first requires an element


<uses-permission android:name="android.permission.INTERNET" />

while the second requires an entry


<uses-library android:name="com.google.android.maps" />

that is a child node of the <application> element. For example,


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lightcone.mapoverlaydemo"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".MapOverlayDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShowTheMap" android:label="Lat/Long Location"> </activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-sdk android:minSdkVersion="3" />
 

</manifest>  

欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!http://www.cnblogs.com/sunshine-anycall/archive/2011/09/16/2178227.html
相关文章
|
23天前
|
API Docker 容器
如何免费获取 ChatGPT API Key?
上篇文章介绍了NextChat项目,只需配置ChatGPT API Key即可拥有私人ChatGPT网页应用。本文继续介绍免费获取API Key的来源——GPT_API_free,一个拥有13.6K Star的Github开源项目。需用Github账号绑定领取Key,支持gpt-3.5-turbo、embedding、gpt-4,但gpt-4每天限3次调用。GPT_API_free也提供付费版API,以支持项目持续运营。
189 0
如何免费获取 ChatGPT API Key?
|
7月前
|
Android开发
如何在Android真机上检测是否有Google Map add-on
如何在Android真机上检测是否有Google Map add-on
76 3
|
4月前
|
开发工具 Android开发
上架Google Play报错:For new apps, Android App Bundles must be signed with an RSA key.
上架Google Play报错:For new apps, Android App Bundles must be signed with an RSA key.
128 1
|
4月前
|
API 网络架构 C++
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
|
4月前
|
API 开发工具
langchain 入门指南(一)- 准备 API KEY
langchain 入门指南(一)- 准备 API KEY
259 0
|
5月前
|
人工智能 自然语言处理 数据挖掘
详解:Google AI Gemini中文版本(基于API 开发实现对话)
谷歌旗下的人工智能应用Gemini,自问世以来凭借其强大的计算能力和高效的处理性能,迅速成为全球用户的宠儿。作为一款由世界顶尖科技公司开发的产品,Gemini不仅在语言处理、图像识别、数据分析等领域表现出色,还在多种复杂任务中展现了其卓越的智能决策能力。然而,由于网络限制等问题,国内用户往往无法直接访问和使用Gemini的网站,这也导致了许多技术爱好者和专业人士未能亲身体验这一先进技术所带来的便利和强大功能。
|
6月前
|
文字识别 算法 API
视觉智能开放平台产品使用合集之Secret Key(AccessKey Secret)和 API KEY(AccessKey ID)该如何申请
视觉智能开放平台是指提供一系列基于视觉识别技术的API和服务的平台,这些服务通常包括图像识别、人脸识别、物体检测、文字识别、场景理解等。企业或开发者可以通过调用这些API,快速将视觉智能功能集成到自己的应用或服务中,而无需从零开始研发相关算法和技术。以下是一些常见的视觉智能开放平台产品及其应用场景的概览。
|
6月前
|
域名解析 JavaScript 网络协议
技术心得记录:如何使用google地图的api(整理)
技术心得记录:如何使用google地图的api(整理)
464 0
|
7月前
|
Java Shell Android开发
android 权限申请
android 权限申请
120 5
|
7月前
|
API Android开发
android setTag (int key, Object tag)使用
android setTag (int key, Object tag)使用
67 1