Hello World
This sample demonstrates an android application with map viewer. The application loads a worldwide street cached data map on an android device with zoom in, zoom out, and pan operations. This is achieved by adding a mapview object, which is the main mapping component of the ArcGIS API for Android.
How to use:
See How to work with samples for more information on running this sample on Eclipse IDE.
The class is based on Android's Activity class and calls onCreate() method to perform. Android activity is overriden to include map control.
public class HelloWorld extends Activity {
MapView map = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView) findViewById(R.id.map);
The initial extent for map to zoom is set in res\layout\main.xml.
<?xml version="1.0" encoding="utf-8"?>
<com.esri.android.map.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map" android:layout_width="fill_parent"
android:layout_height="fill_parent"
initExtent="-1.3296373526814876E7 3930962.41823043 -1.2807176545789773E7 4201243.7502468005">
The map center and resolution is persisted by onRetainNonConfigurationInstance’ method and restored in ‘onCreate’ method. The helps to maintain map's desired state to propagate to the next activity instance.
/** Called by the system, as part of destroying an activity due to a configuration change. */
@Override
public Object onRetainNonConfigurationInstance() {
return map.retainState();
}
You can retrieve the map's state from the previous instance by 'getLastNonConfigurationInstance' method.
/** Called by the system, as part of destroying an activity due to a configuration change. */
Object init = getLastNonConfigurationInstance();
if (init != null) {
map.restoreState((String) init);
You have a map viewer application running on android. Here is the list of actions you can try to see how zoom and pan operations work by default:
- Try double tap on the map, notice that the map zooms into the location that was double tapped-on.
- Try pinch-in with two fingers on the map, notice that the map zooms out.
- Try pinch-out with two fingers on the map, notice that the map zooms in to that location.
- Try giving a flick by the tip of your finger, notice that the map pans in that direction.
- Tap on map once and drag, notice that the map pans to that location.