4. Code implementations

Feedback


  1. Add permissions in AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  1. Add Android support in AndroidManifest.xml
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8"/>
  1. Add map controls in the layout xml (GettingStarted \ res \ layout \ iclient_android_app.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
   <com.supermap.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:enabled="true"/>
</RelativeLayout>
  1. Let the created GettingStartedActivity (auto-generated) inherit Activity and import the related classes
package com.supermap.sample;
import com.supermap.android.maps.LayerView;
import com.supermap.android.maps.MapView;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
public class GettingStartedActivity extends Activity {
        // Maps provided by SuperMap iServer use a fixed address for delivering
        private static final String DEFAULT_URL = "http://192.168.120.41:8091/iserver/services/map-china400/rest/maps/China";
        protected MapView mapView;
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
              setContentView(R.layout.iclient_android_app);
        }
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
                super.onConfigurationChanged(newConfig);
        }
}
  1. Initialize GettingStartedActivity and add the following codes in onCreate:
                //Create a mapview
                mapView = (MapView) this.findViewById(R.id.mapview);
                //Create a map layer and point at map services provided by iServer
                LayerView layerView = new LayerView(this);
                layerView.setURL(DEFAULT_URL);
                //Set map scaling
                mapView.setBuiltInZoomControls(true);
                //Load a map layer
                mapView.addLayer(layerView);

 

Refer to