申请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

时间: 2024-10-26 12:02:48

申请google android map api key的相关文章

android map如何获得Google Map API key

首先要做的是获取一个MD5 key(当然,他是通过JDK的keytool工具(keytool.exe)实现的) 1.在这里,主要有两方面的工作 keytool.debug.keystore 2.首先,找到debug.keystore!(进入Eclipse开发环境,然后选择Window-->Preferences-->Android-->Build,这时候我们可以看到界面中的Default debug keystore,它后面方框中的内容就是debug.keystore的路径).在此,我们

Android开发如何获取google Map API Key

地图应用使用com.google.android.maps这个包.通过MapView控件使用.但是之前需要申请一个用于开发的API Key,这个key会和当前的计算机用户绑定.然后通过这个key去官方申请就可以拿到一个开发用的api key了 <1>首先找到用户的debug.keystore文件,可以再"运行"里面搜debug.keystore;如:c:usersAdministrator.androiddebug.keystore <2>接下来获取MD5指纹,

关于Google Map API Key

问题描述 在CMD执行命令keytool-list-keystoredebug.keystore,只出现证书指纹(SHA1),没有MD5值,无法申请MapAPIKey,求高手指导!

申请Google Map Android API Key

要想使用Google的Map服务编写应用,无论是Google Map API和Google Map Android API都需要申请Key.Google Map API中的Key的申请这里就不介绍了,主要介绍Google Map Android API的Key,它的申请步骤如下:• 找到或创建keystore证书文件:• 生成MD5认证指纹:• 生成Google Map API Key.1.找到或创建keystore证书文件我们在本书的第3章的应用程序的打包.安装和卸载部分已经介绍了,本章就不再

android开发google map申请不到google map 的api key

问题描述 android开发google map申请不到google map 的api key 本地的MD5指纹已经获取到了,可是在google网站上申请google map api key时遇到了问题.去网上搜索了下,说申请google map api key的新网址是https://developers.google.com/android/maps-api-signup?hl=zh-CN,可是直接转到了一个duocumentation页面,在上面逛了半天没有找到头绪.恳请各位大神帮忙,告知

Android studio 开发,谷歌 API Key 如何 申请?

问题描述 Android studio 开发,谷歌 API Key 如何 申请? 在用Android studio开发过程中, 需要用到谷歌地图,请问怎么申请谷歌 API Key 了?帮帮忙!!! 解决方案 申请Google Map Android API Key申请 ANDROID GOOGLE MAP API KEY 解决方案二: 建议用BaiduMap等墙内的地图 解决方案三: 建议用高德地图,坐标跟google的算法是一个.

基于google map api开发web和google earth的KML地标插件

KML文件很好做,在你的google earth(以下简称GE)中选择你自己的或是别人的marker或layer,就可以保存成静态的地标或图层信息(kmz或kml格式),发送给你的朋友,用他的GE打开你的文件就可以看到你所标注的marker信息. 这些相关的文章让我迷失了好一段时间,不过,我想要的是动态的地标.类似于EEMAP那样的GE插件.下面我将讲述它的工作原理和制做方法. 先说几个概念,google map api是基于javascript+xml等技术实现的,另一款产品google ea

google map api 简单地图定位实例

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-

google maps-如何在 google map 中找 API key ?

问题描述 如何在 google map 中找 API key ? <?xml version=""1.0"" encoding=""utf-8""?><com.google.android.maps.MapView xmlns:android=""http://schemas.android.com/apk/res/android"" android:id="