閱讀577 返回首頁    go 技術社區[雲棲]


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

1、下載解壓eclipse

2、安裝ADT

3、安裝Android SDK

4、安裝和配置Google Play services SDK

GoogleMaps Android API v2作為Google Play Services的一部分被分發,可以通過AndroidSDK Manager下載GooglePlay 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>元素內

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

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”。

<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="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>元素的一個子元素。

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

8、添加地圖測試配置

(1)       用如下代碼替換res/layout/activity-main.xml文件中的全部內容

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="https://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中添加如下代碼

package com.example.mapdemo;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

(3)       建立和運行程序。

 

最後更新:2017-04-03 12:54:34

  上一篇:go DEV GridView顯示行號
  下一篇:go DEV Gridcontrol 查詢得到0條記錄時顯示自定義的字符提示/顯示