在地图开发中,我们熟悉的有高德、百度与腾讯地图,另外还有Google地图等,都提供了比较全面的SDK。而对于Arcgis开发地图还是比较陌生。本着好奇的态度学习对Arcgis的开发。
Android Arcgis开发首先要下载Arcgis SDK,下载地址在Arcgis官网https://developers.arcgis.com/,不过下载要注册,比较麻烦。可以从http://download.csdn.net/detail/gary__123456/9787775,下载jar包与so文件。学习采用的版本是Arcgis SdK 10.2.4。下载jar与so后,进入正题,新启项目Arcgis Demo。
1.添加so与jar,如图:
2.工程的Mainfest文件中添加相应的权限:
<uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />3.build.gradle文件下的android节点加上如下配置:解决jackson-mapper-lgpl-1.9.5.jar与jackson-core-lgpl-1.9.5.jar无法编译问题
packagingOptions { exclude 'META-INF/LGPL2.1' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' }
在MainActivity的布局中添加MapView控件,并加上id.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.arcgis.test.MainActivity"> <com.esri.android.map.MapView android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>在MainActivity中获取控件,并添加一个开放的网络图层。利用ArcGISTiledMapServiceLayer图层添加。
private MapView mMapView; private String mapServerUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMapView = (MapView) findViewById(R.id.map_view); addLayer(); } private void addLayer() { ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapServerUrl); mMapView.addLayer(arcGISTiledMapServiceLayer); } protected void onResume() { super.onResume(); mMapView.unpause(); } @Override protected void onPause() { super.onPause(); mMapView.pause(); }运行项目,效果图如下。Arcgis 在Studio中基本配置就到这里。