• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Maps SDK Configuration

The Android Maps SDK allows developers to create maps in their applications using the NextbillionMapOptions configuration. This configuration class defines the default values and states for a MapView, providing various options for customization. With NextbillionMapOptions, developers can easily configure the maps in their applications to meet their specific needs.

Configurations

The Android Maps SDK offers the following available configurations.

Camera

The below code snippet is a part of the Camera class in the Android Maps SDK. It defines several variables used to control the camera view of a map. The cameraPosition variable stores the current camera position of the map, while the minZoom and maxZoom variables set the minimum and maximum zoom level allowed. The minPitch and maxPitch variables set the minimum and maximum pitch angle of the camera. These variables work together to control the camera view of the map and ensure that it stays within the desired range of values. The values are taken from the NbmapConstants class, which provides constants that define the minimum and maximum values for various parameters in the map view.

1 private CameraPosition cameraPosition;
2 private double minZoom = NbmapConstants.MINIMUM_ZOOM;
3 private double maxZoom = NbmapConstants.MAXIMUM_ZOOM;
4 private double minPitch = NbmapConstants.MINIMUM_PITCH;
5 private double maxPitch = NbmapConstants.MAXIMUM_PITCH;

cameraPosition: The initial coordinate of a MapView will be at (0, 0), we can configure the initial coordinate with this field. Meanwhile, cameraPosition has defined these configurable values:

1 public final double bearing;
2
3 /**
4 * The location that the camera is pointing at.
5 */
6 public final LatLng target;
7
8 /**
9 * The angle, in degrees, of the camera angle from the nadir (directly facing the Earth).
10 */
11 public final double tilt;
12
13 /**
14 * Zoom level near the center of the screen.
15 */
16 public final double zoom;
17
18 /**

The other fields are straightforward, and define a range of supported zoom and pitch/tilt of a MapView.

UI control

1 private boolean compassEnabled = true;
2 private boolean fadeCompassFacingNorth = true;
3 private int compassGravity = Gravity.TOP | Gravity.END;
4 private int[] compassMargins;
5 private Drawable compassImage;
6
7 private boolean logoEnabled = true;
8 private int logoGravity = Gravity.BOTTOM | Gravity.START;
9 private int[] logoMargins;
10 @ColorInt
11 private int attributionTintColor = UNDEFINED_COLOR;
12 private boolean attributionEnabled = true;
13 private int attributionGravity = Gravity.BOTTOM | Gravity.START;
14 private int[] attributionMargins;

The configuration defines gravity, margins, and toggle-flag for Compass, Logo, and Attribution.

The "fadeCompassFacingNorth" flag is set to "true", which means the compass icon on the map view will be hidden when the map view is facing north. When this flag is set to "true", the compass will not be visible on the map when it is rotated to face north.

Gestures

The code defines the flags for various gestures that are supported by a map view. Each flag determines whether the corresponding gesture is enabled or not. For example, "rotateGesturesEnabled" is set to "true", which means that the map view will support the gesture of rotating. Similarly, "scrollGesturesEnabled" is set to "true", which means the map view will support the gesture of scrolling. The other flags (horizontalScrollGesturesEnabled, tiltGesturesEnabled, zoomGesturesEnabled, doubleTapGesturesEnabled, and quickZoomGesturesEnabled) have the same purpose and determine whether their respective gestures are supported in the map view.

1 private boolean rotateGesturesEnabled = true;
2 private boolean scrollGesturesEnabled = true;
3 private boolean horizontalScrollGesturesEnabled = true;
4 private boolean tiltGesturesEnabled = true;
5 private boolean zoomGesturesEnabled = true;
6 private boolean doubleTapGesturesEnabled = true;
7 private boolean quickZoomGesturesEnabled = true;

These are flags to turn on and off for supported gestures.

Base URI & Map Tiles

1The code is for a mapping application and defines several variables for the SDK.
2 private String apiBaseUri;
3 private boolean prefetchesTiles = true;
4 private int prefetchZoomDelta = 4;
5 @ColorInt
6 private int foregroundLoadColor;

The "apiBaseUri" variable specifies the host for the Maps SDK to connect to. The "prefetchesTiles" and "prefetchZoomDelta" variables control the behavior of map tile prefetching. Finally, the "foregroundLoadColor" variable determines the color of the page before the map tile is loaded.

Glyphs and Font

1 private boolean localIdeographFontFamilyEnabled = true;
2 private String localIdeographFontFamily;
3 private String[] localIdeographFontFamilies;

This code snippet declares three variables related to font handling:

  • localIdeographFontFamilyEnabled: a boolean variable that determines whether the local ideograph font family is enabled. If set to true, it means that the local ideograph font family is enabled.
  • localIdeographFontFamily: a string variable that stores the name of the local ideograph font family.
  • localIdeographFontFamilies: an array of strings that holds the names of the local ideograph font families.

How to configure

Configure from XML

If we add a MapView from XML layout, we can configure the maps in this way:

1 <ai.nextbillion.maps.core.MapView
2 android:id="@id/mapView"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 app:nbmap_baseUri="https://api.nextbillion.io"
6 app:nbmap_cameraTargetLat="12.99150562"
7 app:nbmap_cameraTargetLng="77.61940507"
8 app:nbmap_cameraZoom="10" />

This code defines an XML layout that adds a MapView component. This component is part of the NextBillion maps library and is used to display a map on the screen. The MapView component is specified with the following attributes:

  • android: an ID used to uniquely identify the MapView component in the layout.
  • android and android: the width and height of the MapView component, respectively. They are set to match_parent which means the component will occupy the entire parent layout.
  • app: the base URL used to access the NextBillion maps API. The value is set to https://api.nextbillion.io.
  • app and app: the latitude and longitude of the target location to be displayed on the map, respectively. The values are set to 12.99150562 and 77.61940507.
  • app: the zoom level of the camera. The value is set to 10, which means that the map will be zoomed in to a level where objects on the map will appear 10 times larger than at the default zoom level.

This XML layout is used to configure the display of the map, including the URL of the API, the location to be displayed, and the zoom level.

Available attributes

The Android Maps SDK provides a rich set of attributes that allow developers to customize the appearance and behavior of maps in their applications. These attributes provide fine-grained control over various aspects of maps, such as camera position, zoom level, map style, and markers. With these attributes, developers can create maps that meet the specific needs of their applications and provide a seamless user experience. By using the available attributes, developers can ensure that their maps are visually appealing and provide accurate and up-to-date information.

1 <!--Camera-->
2 <attr name="nbmap_cameraTargetLat" format="float" />
3 <attr name="nbmap_cameraTargetLng" format="float" />
4 <attr name="nbmap_cameraZoom" format="float" />
5 <attr name="nbmap_cameraBearing" format="float" />
6 <attr name="nbmap_cameraTilt" format="float" />
7 <attr name="nbmap_cameraZoomMax" format="float" />
8 <attr name="nbmap_cameraZoomMin" format="float" />
9 <attr name="nbmap_cameraPitchMax" format="float" />
10 <attr name="nbmap_cameraPitchMin" format="float" />
11
12 <!--Gestures-->
13 <attr name="nbmap_uiZoomGestures" format="boolean" />
14 <attr name="nbmap_uiScrollGestures" format="boolean" />
15 <attr name="nbmap_uiHorizontalScrollGestures" format="boolean" />
16 <attr name="nbmap_uiRotateGestures" format="boolean" />
17 <attr name="nbmap_uiTiltGestures" format="boolean" />
18 <attr name="nbmap_uiDoubleTapGestures" format="boolean" />

Configure programmatically

The Android Maps SDK provides the ability to programmatically integrate maps into an application by using the MapView class. To configure the map display, developers can create an instance of NextbillionMapOptions and pass it when creating a MapView.

One way to create a default NextbillionMapOptions is by calling the static method NextbillionMapOptions.createFromAttributes(Context context). This method creates an instance of NextbillionMapOptions with default settings based on the current context.

Once an instance of NextbillionMapOptions is created, it can be customized by calling the available setters. For example, in the code snippet:

1NextbillionMapOptions options = NextbillionMapOptions.createFromAttributes(this, null)
2 .attributionTintColor(BLUE_COLOR)
3 .apiBaseUri("https://api.nextbillion.io")
4 .compassFadesWhenFacingNorth(false)
5 .camera(new CameraPosition.Builder()
6 .target(new LatLng(5.727531563481325, 102.11544099540563))
7 .zoom(7)
8 .tilt(0)
9 .build());
10
11mapView = new MapView(this, options);

The NextbillionMapOptions instance is created with the default settings and then modified to set the attribution tint color to blue, the API base URI to https://api.nextbillion.io, to prevent the compass from fading when facing north, and to set the camera position to a specific location with a zoom level of 7 and a tilt of 0 degrees.

Finally, the MapView is created by passing the customized NextbillionMapOptions instance.

Available setters

The Android Maps SDK provides a comprehensive set of setters that allow developers to fully customize the appearance and behavior of maps in their applications. These setters offer fine-grained control over various aspects of maps, such as camera position, zoom level, map style, and markers. With these setters, developers can create maps that meet the specific needs of their applications and provide a seamless user experience.

1//Camera
2public NextbillionMapOptions camera(CameraPosition cameraPosition)
3public NextbillionMapOptions minZoomPreference(double minZoom)
4public NextbillionMapOptions maxZoomPreference(double maxZoom)
5public NextbillionMapOptions minPitchPreference(double minPitch)
6public NextbillionMapOptions maxPitchPreference(double maxPitch)
7
8//UI control
9public NextbillionMapOptions compassEnabled(boolean enabled)
10public NextbillionMapOptions compassGravity(int gravity)
11public NextbillionMapOptions compassMargins(int[] margins)
12public NextbillionMapOptions compassFadesWhenFacingNorth(boolean compassFadeWhenFacingNorth)
13public NextbillionMapOptions compassImage(Drawable compass)
14public NextbillionMapOptions logoEnabled(boolean enabled)
15public NextbillionMapOptions logoGravity(int gravity)
16public NextbillionMapOptions logoMargins(int[] margins)
17public NextbillionMapOptions attributionEnabled(boolean enabled)
18public NextbillionMapOptions attributionGravity(int gravity)