Gradle
1. 添加 Esri's maven
在 Project 的 build.gradle 中添加
allprojects {
repositories {
google()
jcenter()
// Add the Esri public Bintray Maven repository
maven {
url 'https://esri.bintray.com/arcgis'
}
}
}
2. 添加依赖
在 Module 的 build.gradle 中添加
dependencies {
implementation 'com.esri.arcgisruntime:arcgis-android:100.3.0'
[...]
}
3.Java 8 的支持
android {
[...]
// Add below lines to set compatibility with Java 8 language features for an Android app module.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
4.权限
Android API 版本在 23 之后,需要对危险权限添加运行时申请
除了一般的权限申请,需要在 AndroidManifest.xml 中添加 uses-feature element 申请 OpenGL 的权限.
使用GeoView 需要 OpenGL2.x 时
使用 ViewShed 或者 LineOfSight 需要 OpenGL3.x
5.添加 MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
设置 MapView
mMapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 34.056295, -117.195800, 16);
mMapView.setMap(map);
生命周期管理
@Override
protected void onPause(){
mMapView.pause();
super.onPause();
}
@Override
protected void onResume(){
super.onResume();
mMapView.resume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.dispose();
}