Skip to Content

Display Customer Locations Using a Fiori Map Control

Further customize the generated app to display customer locations on a map and try out the features of the Fiori Map control, including the toolbar, map panel, clustering, and map annotation.
You will learn
  • How to add a Google Map to the wizard-generated app and display customer locations
  • How to add a Fiori Map control and try out its features
flyingfish162Bruce MengMarch 31, 2025
Created by
sandeep-tds
January 9, 2023
Contributors
sandeep-tds
flyingfish162

Prerequisites

You have:
1. Set Up a BTP Account for Tutorials. Follow the instructions to get an account, and then to set up entitlements and service instances for the following BTP services.
- SAP Mobile Services
2. Completed Try Out SAP BTP SDK Wizard for Android.

A Fiori Map control extends the Google Maps SDK for Android. It provides additional APIs that handle clustering, as well as a toolbar, panel, and an editor to annotate map. For additional details, see Fiori Design Guidelines.

  • Step 1

    In this section you will create a new activity to display a map.

  • Step 2

    In this section, you will add code to place a marker on the map for each customer.

    Based on the where statement, customers from which countries are shown on the map?

  • Step 3

    In this section, you will add code to display the customer detail screen when the info marker is tapped.

  • Step 4

    In this section, you will create a new activity that uses the Fiori Map control.

    What are some differences between the Google map activity and Fiori Google map activity?

  • Step 5

    In this section, the bottom panel will be populated with details of the selected marker and an action will be implemented to enable navigation to the selected customer’s detail page.

  • Step 6

    In this section you will implement the settings dialog to include a map type setting and a clustering toggle.

    1. Create a new Layout Resource File in res/layout called settings_panel.xml and replace its contents with the following code. This creates the layout for the settings page.

      XML
      Copy
      <?xml version="1.0" encoding="utf-8"?>
      <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_gravity="fill_horizontal"
                  android:orientation="horizontal">
      
                  <com.sap.cloud.mobile.fiori.formcell.ChoiceFormCell
                      android:id="@+id/map_type"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      app:key="Map Type" />
      
              </LinearLayout>
      
              <com.sap.cloud.mobile.fiori.formcell.SwitchFormCell
                  android:id="@+id/use_clustering"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:showText="true"
                  app:key="Clustering"
                  app:value="true" />
      
          </LinearLayout>
      </ScrollView>
      
    2. On Windows, press Ctrl+N, or, on a Mac, press command+O, and type CustomersFioriMapActivity to open CustomersFioriMapActivity.kt.

    3. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type onMapCreated to navigate to the onMapCreated method.

    4. Find the following line of code:

      Kotlin
      Copy
      mActionProvider.setClustering(false)
      
    5. Replace the line above with the following code:

      Kotlin
      Copy
      val settingsView = inflater.inflate(R.layout.settings_panel, null)
      
      // Setup selection of a different map type
      val mapTypeChoice = settingsView.findViewById<ChoiceFormCell>(R.id.map_type)
      mapTypeChoice.valueOptions = arrayOf<String>("Normal", "Satellite", "Terrain", "Hybrid")
      mapTypeChoice.cellValueChangeListener = object : FormCell.CellValueChangeListener<Int>() {
          override fun cellChangeHandler(value: Int?) {
              value?.let {
                  when (it) {
                      0 -> mMapType = GoogleMap.MAP_TYPE_NORMAL
                      1 -> mMapType = GoogleMap.MAP_TYPE_SATELLITE
                      2 -> mMapType = GoogleMap.MAP_TYPE_TERRAIN
                      3 -> mMapType = GoogleMap.MAP_TYPE_HYBRID
                  }
                  mGoogleFioriMapView.map?.mapType = mMapType
              }
          }
      }
      
      if (mMapType == 0) {
          mapTypeChoice.value = mMapType
      } else {
          mapTypeChoice.value = mMapType - 1
      }
      
      mGoogleFioriMapView.setSettingsView(settingsView)
      
      if (mMapType != GoogleMap.MAP_TYPE_NONE) {
          mGoogleFioriMapView.map?.mapType = mMapType
      }
      
      // Setup clustering selection.
      val useClusteringSwitch = settingsView.findViewById<SwitchFormCell>(R.id.use_clustering)
      useClusteringSwitch.value = mUseClustering
      mActionProvider.setClustering(mUseClustering)
      useClusteringSwitch.cellValueChangeListener = object: FormCell.CellValueChangeListener<Boolean>() {
          override fun cellChangeHandler(value: Boolean?) {
              value?.let {
                  mUseClustering = it
                  mActionProvider.setClustering(mUseClustering)
              }
          }
      }
      
    6. Run the app.

    7. Tap on the settings icon in the toolbar.

      Setting icon in toolbal
    8. Change the map type to Hybrid and turn Clustering on.

      Settings
      Hybrid map example

      Notice that the markers in close proximity are now grouped together and a number indicates how many markers are in the cluster.

      Map panel for Cluster

    Congratulations! You have now successfully added a Fiori Map to an application and tried out some of the features it provides.

    What is clustering?

  • Step 7

    In this section, you will test the three different types of annotations.

    In order to redraw the points the next time the map is opened, you must save and store them in the app using the on save click listener.

    What type of annotations can you draw on the map?

  • Step 8

    In this section you will customize the map markers based on the customer’s country. The different marker colors will be recorded in the legend as well.

    1. On Windows, press Ctrl+N, or, on a Mac, press command+O, and type CustomersFioriMapActivity to open CustomersFioriMapActivity.kt.

    2. On Windows, press Ctrl+F12, or, on a Mac, press command+F12, and type addCustomerMarkerToMap to navigate to the addCustomerMarkerToMap method.

    3. Replace the method with the following code:

      Kotlin
      Copy
      private fun addCustomerMarkerToMap(customer: Customer) {
          val country = customer.country
          getCustomerLatLongFromAddress(customer.city + ", " + country)?.let { latLng ->
              var color = (Color.parseColor("#E9573E")) // US
              if (country == "MX") {
                  color = (Color.parseColor("#FFA02B"))
              } else if (country == "CA") {
                  color = Color.parseColor("#0070F2")
              }
              val customerMarker = FioriMarkerOptions.Builder()
                  .tag(customer)
                  .point(FioriPoint(latLng.latitude, latLng.longitude))
                  .title(customer.firstName + " " + customer.lastName)
                  .legendTitle(customer.country)
                  .color(color)
                  .build()
              mActionProvider.addMarker(customerMarker)
              markers[customer.city + ", " + customer.country] = customerMarker
              mGoogleFioriMapView.map?.moveCamera(CameraUpdateFactory.newLatLng(latLng))
          }
      }
      
    4. Run the app.

      The markers now have different colors depending on whether they are located in Canada (CA), the United States (US), or Mexico (MX). The meaning of the colors is shown in the legend.

      Marker Legend

      With clustering enabled, notice that clustered markers turn white if the markers in the cluster are located in different countries.

    Congratulations. You have now seen how an app can make use of the Fiori map control.


    What object is used to customize markers?

Back to top