申请Google Map服务



 

要想使用Google Map,那么必定须要注册一个Google的通行证,注册地址:java

https://accounts.google.com/ServiceLoginAuthandroid

  若是要申请Goolge Map服务,那么必须生成一个MD5指纹码,而这个指纹码,能够api

经过debug.keystore生成。app

  这个是一个签名的文件,对于全部的Android程序而已必须有此文件才能够打包编译,ide

而在一个Android虚拟机创建完成以后会自动的在一个目录中生成此文件,此目录通常为:google

C:\Users\Administrator\.android操作系统

  签名文件的有效期是1年,1年以后若是没有从新作系统,那么这个文件就没法再自动的debug

进行Android程序的打包操做,此时只能将此文件删除,以后会自动生成一个新的,这样xml

有能够继续使用1年。blog

  每一台电脑都要申请属于本身的android:apiKey,要是使用别人的android:apiKey,

则地图只显示方格,不会有实际的地图出现,而且在Android虚拟机重建或者重装电脑的操做系统的时候

也要从新申请android:apiKey,关于如何申请,我在“申请Google Map服务”中已说得很详细。

 

申请Google Map Android API Key:

 

一、进入https://accounts.google.com/ServiceLoginAuth申请google通行证,

我申请得的帐号为:liyewen1988@gmail.com;

二、生成证书指纹(MD5),执行: C:\Users\Administrator\.android,

执行: keytool -list -v -keystore debug.keystore,口令为: android,

我获得的MD5为:   17:5A:46:90:5F:B1:E2:37:DA:12:A0:B5:54:4C:19:56;

三、若是在第4歩输入MD5的地方没有显示出来,则找到本地的hosts文件,在C:\Windows\System32\drivers\etc

目录下,打开hosts文件(修改hosts文件须要管理员权限),往里面最底部加

入203.208.46.180     google-developers.appspot.com;

四、打开网址https://developers.google.com/android/maps-api-signup?hl=zh-CN

五、在已经登陆的状况下将MD5复制进My certificate's MD5 fingerprint中,再选择赞成,最后选择生成;

六、将<com.google.android.maps.MapView

           android:layout_width="fill_parent"

           android:layout_height="fill_parent"

           android:apiKey="0Pm9QrsSh_mwtc6rMyqZMRu71qFpIB51UXVWHmg"/>

复制出来,"0Pm9QrsSh_mwtc6rMyqZMRu71qFpIB51UXVWHmg"这个就是咱们所须要拿到的。

 

 

 

 

新建一个地图项目。

 

 

在main.xml中:

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  android:orientation="vertical" android:layout_width="fill_parent"

  android:layout_height="fill_parent">

  <com.google.android.maps.MapView

     android:clickable="true"

     android:enabled="true"

     android:layout_width="fill_parent"

     android:layout_height="fill_parent"

     android:apiKey="0Pm9QrsSh_mwtc6rMyqZMRu71qFpIB51UXVWHmg" />

</LinearLayout>

 

 

 

 

 

在MyGoogleMapDemo.java中:

 

package com.li.googlemapproject;

 

import android.os.Bundle;

 

import com.google.android.maps.MapActivity;

 

public class MyGoogleMapDemo extends MapActivity {

  @Override

  public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);

     super.setContentView(R.layout.main);

  }

 

  @Override

  protected boolean isRouteDisplayed() {

     return false;

  }

}

 

 

 

 

在AndroidManifest.xml中修改权限:

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.li.googlemapproject"

    android:versionCode="1"

    android:versionName="1.0" >

 

    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="15" />

    <application

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name=".MyGoogleMapDemo"

            android:label="@string/title_activity_my_google_map_demo" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

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

    </application>

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

</manifest>