申请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: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!












本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/archive/2011/09/16/2178227.html ,如需转载请自行联系原作者




相关文章
|
4月前
|
存储 API
Map常用API
Map常用API
38 2
|
1月前
|
存储 Java API
Java交换map的key和value值
通过本文介绍的几种方法,可以在Java中实现Map键值对的交换。每种方法都有其优缺点,具体选择哪种方法应根据实际需求和场景决定。对于简单的键值对交换,可以使用简单遍历法或Java 8的Stream API;对于需要处理值不唯一的情况,可以使用集合存储或Guava的Multimap。希望本文对您理解和实现Java中的Map键值对交换有所帮助。
37 1
|
4月前
|
存储 算法 Java
Go 通过 Map/Filter/ForEach 等流式 API 高效处理数据
Go 通过 Map/Filter/ForEach 等流式 API 高效处理数据
|
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.
130 1
|
5月前
|
存储 数据库 Android开发
🔥Android Jetpack全解析!拥抱Google官方库,让你的开发之旅更加顺畅无阻!🚀
【7月更文挑战第28天】在Android开发中追求高效稳定的路径?Android Jetpack作为Google官方库集合,是你的理想选择。它包含多个独立又协同工作的库,覆盖UI到安全性等多个领域,旨在减少样板代码,提高开发效率与应用质量。Jetpack核心组件如LiveData、ViewModel、Room等简化了数据绑定、状态保存及数据库操作。引入Jetpack只需在`build.gradle`中添加依赖。例如,使用Room进行数据库操作变得异常简单,从定义实体到实现CRUD操作,一切尽在掌握之中。拥抱Jetpack,提升开发效率,构建高质量应用!
84 4
|
4月前
|
安全 Java Android开发
Android 14适配Google play截止时间临近,适配注意点和经验
本文介绍了Android 14带来的关键更新,包括性能优化、定制化体验、多语言支持、多媒体与图形增强等功能。此外,还强调了适配时的重要事项,如targetSdkVersion升级、前台服务类型声明、蓝牙权限变更等,以及安全性与用户体验方面的改进。开发者需按官方指南更新应用,以充分利用新特性并确保兼容性和安全性。
301 0
|
5月前
|
JavaScript API
js【最佳实践】遍历数组的八种方法(含数组遍历 API 的对比)for,forEach,for of,map,filter,reduce,every,some
js【最佳实践】遍历数组的八种方法(含数组遍历 API 的对比)for,forEach,for of,map,filter,reduce,every,some
90 1
|
6月前
|
存储 Java API
探讨Java中交换Map的Key和Value值的技术
探讨Java中交换Map的Key和Value值的技术
54 2
|
6月前
|
存储 缓存 Java
Java交换map的key和value值
在Java中,直接交换`Map`的key和value是不允许的,因为key是唯一的且不可变。不过,可以通过创建新`Map`实现交换:将原`Map`的value作为新key,key作为新value。注意,如果原`Map`有重复value或null,需额外处理。以下是一个代码示例,展示了如何在value唯一且非null的情况下交换`Map`的key和value。对于重复value或null值的情况,可以使用`List`存储多个key或忽略null值。在实际应用中,`Map`常用于缓存、配置管理、数据库结果映射等多种场景。
80 1
|
5月前
|
JSON JavaScript API
JS【详解】Map (含Map 和 Object 的区别,Map 的常用 API,Map与Object 的性能对比,Map 的应用场景和不适合的使用场景)
JS【详解】Map (含Map 和 Object 的区别,Map 的常用 API,Map与Object 的性能对比,Map 的应用场景和不适合的使用场景)
134 0
下一篇
DataWorks