天天看點

谷歌地圖安卓開發環境配置

1、下載下傳解壓eclipse

2、安裝ADT

3、安裝Android SDK

4、安裝和配置Google Play services SDK

詳細步驟:

(1)       安裝Google Play services SDK

(2)       安裝一個相容的Google APIs平台

(3)       将庫項目導入工作區間,庫項目路徑為<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/

(4)       在項目中引用Google Play services

(5)       添加Google Play services版本到程式的manifest

将如下聲明添加到<application>元素内

5、Get an Android certificate and the Google Maps API key

Youobtain a Maps API key from the Google APIs Console by providing yourapplication's signing certificate and its package name. Add the key to yourapplication by adding an element to your application's AndroidManifest.xmlfile.

程式的簽名證書即SHA1fingerprints,可以在windows>preferences>Android>Build中查詢,建立API項目以及擷取GoogleMaps API key在GoogleAPIs Console網站中進行。

6、添加API key到應用程式

在AndroidManifest.xml中添加如下元素作為<application>元素的子元素,在結束标簽</application>之前添加,用擷取的API key替代“API_KEY”。

7、在manifest中指定應用程式設定

一個使用GoogleMaps Android API的安卓應用程式應該在manifest.xml檔案中進行如下設定:

(1)       對Google Play services version的引用。

(2)       程式的Map API key。這個key證明你已經通過Google APIs Console注冊了GoogleMaps service。

(3)       程式通路Android system feature和GoogleMaps servers的許可。除了程式的其他部分要求的許可之外,必須添加如下許可才能使用GoogleMaps Android API。

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

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

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

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<!--The following two permissions are not required to use

     Google Maps Android API v2, but are recommended. -->

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

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

(4)       程式對OpenGL ES version 2的需求。推薦添加如下<uses-feature>元素作為AndroidManifest.xml檔案中<manifest>元素的一個子元素。

8、添加地圖測試配置

(1)       用如下代碼替換res/layout/activity-main.xml檔案中的全部内容

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

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

          android:id="@+id/map"

          android:layout_width="match_parent"

          android:layout_height="match_parent"

          android:name="com.google.android.gms.maps.MapFragment"/>

(2)       在MainActivity.java中添加如下代碼

(3)       建立和運作程式。

轉載:http://blog.csdn.net/foreverling/article/details/18409543

繼續閱讀