1. 程式人生 > >ArcGIS for Android 10.2.9(1):開發環境配置

ArcGIS for Android 10.2.9(1):開發環境配置

官方文件

API

開發環境整合(2中方式)

一.Gradle (推薦)

  1. 使用以下程式碼示例將Maven儲存庫的URL和ArcGIS Runtime SDK for Android依賴項新增到專案中。Esri的儲存庫不是開源的,所以你必須指定一個URL

    在專案的build.grade:

allprojects {
    repositories {
        google()
        jcenter()

        // Add the following ArcGIS repository
        maven {
            url 'https://esri.bintray.com/arcgis'
} } }

2.新增依賴

 // Add ArcGIS Runtime SDK for Android dependency
    implementation 'com.esri.arcgis.android:arcgis-android:10.2.9'

3.應用程式模組build.gradle檔案,在android塊內

packagingOptions { 
    exclude 'META-INF/LGPL2.1' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/NOTICE' 
}

4.新增許可權

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

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

二.整合方式二:下載sdk

三.入門案例

佈局檔案:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.administrator.arcgis1029.Main2Activity">

    <com.esri.android.map.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.esri.android.map.MapView>

</android.support.constraint.ConstraintLayout>

在MainActivity中獲取控制元件,並新增一個開放的網路圖層。利用ArcGISTiledMapServiceLayer圖層新增。

public class Main2Activity extends AppCompatActivity {

    private MapView mMapView;

    private String mapServerUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
    //private String mapServerUrl = "http://192.168.1.228:6080/arcgis/rest/services/jcsj/dzdt/MapServer";

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

        mMapView = (MapView) findViewById(R.id.mapview);

        ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapServerUrl);
        mMapView.addLayer(arcGISTiledMapServiceLayer);
    }

    protected void onResume() {
        super.onResume();
        mMapView.unpause();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }
}

執行專案,效果圖如下:
這裡寫圖片描述

也可以在佈局檔案中直接指定位置:

<com.esri.android.map.MapView
  android:id="@+id/map"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  mapoptions.MapType="Streets"
  mapoptions.center="34.056215, -117.195668"
  mapoptions.ZoomLevel="16">
</com.esri.android.map.MapView>

這裡寫圖片描述