Overview

You will learn: how to display a web map that you created in the Create a web map design lab.

With the ArcGIS Runtime SDK for Android, it is easy to create an app that displays a web map. A web map is special because its format is interchangeable between most applications running on the ArcGIS platform. Web maps are generally created interactively with the Map Viewer and saved in ArcGIS Online. When you save a web map it stores the initial map configuration settings such as the basemap, layer styles, and the pop-up configuration, making it easy for you to load the web map and use the pre-existing settings. This will give you a jump-start building great looking apps. Web maps can also be updated and saved independently from your apps. This is handy if you want to make changes to the map and layers but don't want to make code changes to the app itself.

In this lab, you will use the ArcGIS Android SDK to build a simple mapping app that loads and displays a web map.

Before you begin

Make sure you have installed the latest version of Android Studio.

Reuse the starter project

In a new or empty project folder, make a copy of the Create a starter app or download and unzip the project solution.

  • Open the new Android project in Android Studio.

  • Run the project and verify the project builds and the map displays on the device simulator.

  • You may be required to sync the project dependencies.

Steps

Add a web map to the map

  1. In the file app > java > {your.package.name} > MainActivity.java, add a new method to create a map object from a web map given its URL.

     private void showWebMap() {
         String itemId = "41281c51f9de45edaf1c8ed44bb10e30";
         String url = "https://www.arcgis.com/sharing/rest/content/items/" + itemId + "/data";
         ArcGISMap map = new ArcGISMap(url);
         mMapView.setMap(map);
     }
    
  2. In the same file, find the onCreate method, then call your new method after creating the MapView.

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         mMapView = findViewById(R.id.mapView);
         // *** ADD *** update existing code
         showWebMap();
    

Congratulations, you're done!

Your map should show parks and trails in the Los Angeles area.

Challenge

Use your web map

Instead of using the web map we prepared, use the web map you made in the design lab Create a Web Map (2D).

Replace the itemId variable with the id of your own web map.

Change your map design

Open your web map in the map viewer, make changes to your map design, then save your map. Next time you load that map in your app your changes will be reflected.