SDK Interface

NextbillionMap is an interactable interface of the MapView, each MapView instance will have one associated instance of NextbillionMap.

We can get the reference of NextbillionMap that belongs to a current MapView in the callback of OnMapReadyCallback.

With NextbillionMap we can make changes to the current MapView, which includes:

  • Get basic information about the current MapView
  • Scroll the current MapView
  • Style management
  • Perform camera control
  • Annotations management
  • Manage multiple gesture listeners
  • Manage InfoWindow
  • Query rendered features
  • Obtain reference of UiSettings
  • Obtain reference of Projection

With NextbillionMap, developers have a comprehensive solution for adding location intelligence and mapping capabilities to their Android mobile applications.

Interface

The NextbillionMap Interface is a powerful tool for developers to integrate maps and location services into their Android mobile applications. It provides a user-friendly interface and a wide range of features. The SDK is designed to be highly customizable, allowing developers to create unique and interactive mapping experiences for their users. With the NextbillionMap Android Map SDK, developers can add location intelligence and mapping capabilities to their apps, enabling users to explore, discover and interact with the world around them in new and innovative ways.

Get basic information about the current MapView

The getHeight() and getWidth() methods in the NextbillionMap Android Map SDK Interface provide basic information about the current MapView by returning its height and width respectively. The height and width of a MapView are returned as floating-point values, indicating the dimensions of the view in device-independent pixels.

1
public float getHeight()
2
public float getWidth()

By calling these methods, developers can retrieve the current dimensions of the MapView, which can be useful for various purposes such as adjusting the display of annotations or other elements within the map. For example, a developer could use the MapView's height and width to determine the ideal size for markers or other visual elements on the map, ensuring that they are displayed optimally on any screen size.

Scroll the current MapView

1
public void scrollBy(float x, float y)
2
public void scrollBy(float x, float y, long duration)

The scrollBy(float x, float y) and scrollBy(float x, float y, long duration) methods in the NextbillionMap Android Map SDK Interface allow developers to control the movement of the MapView. These methods scroll the MapView by a specified distance in the x and y directions and offer a choice between an immediate scroll or a smooth animated scroll with a specified duration. This allows developers to easily navigate the MapView programmatically and create an interactive mapping experience for the user.

Style management

The NextbillionMap Android Map SDK Interface provides several methods for managing the style of the MapView, including retrieving, setting, and updating the style as needed.

1
public Style getStyle()
2
public void getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded)
3
public void setStyle(String style)
4
public void setStyle(String style, final Style.OnStyleLoaded callback)
5
public void setStyle(Style.Builder builder)
6
public void setStyle(Style.Builder builder, final Style.OnStyleLoaded callback)

The getStyle() method returns the current style of the MapView. This method can be useful for retrieving the current style for further processing or for storing it for later use. For more advanced style management, the getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded) method allows developers to retrieve the style of the MapView asynchronously, providing a callback to handle the loaded style.

The setStyle(String style) and setStyle(String style, final Style.OnStyleLoaded callback) methods allow developers to set the style of the MapView using a JSON string that defines the style. The second method provides a callback to handle the loaded style. In addition, the setStyle(Style.Builder builder) and setStyle(Style.Builder builder, final Style.OnStyleLoaded callback) methods allow developers to programmatically build and set the style of the MapView using the Style.Builder class. The second method provides a callback to handle the loaded style.

In summary, the style management methods in the NextbillionMap Android Map SDK Interface provide a comprehensive solution for customizing the appearance of the MapView and for working with the styles of the map. These methods allow developers to easily retrieve, set, and update the styles of the MapView, providing a flexible and powerful way to control the look and feel of the map.

For more details of Style, please refer to SDK Style and GeoJSON.

Perform camera control

This code provides functionality for controlling the camera in a map view. The methods allow you to set the camera position, set a LatLngBounds or Geometry to focus on, and retrieve the current camera position. There are also methods to add or remove listeners for camera movement events, such as onCameraIdle, onCameraMoveStarted, onCameraMoveCanceled, and onCameraMove.

1
public void setLatLngBoundsForCameraTarget(@Nullable LatLngBounds latLngBounds)
2
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds)
3
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds,
4
@NonNull @Size(value = 4) int[] padding)
5
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds,
6
@FloatRange(from = NbmapConstants.MINIMUM_DIRECTION,
7
to = NbmapConstants.MAXIMUM_DIRECTION) double bearing,
8
@FloatRange(from = NbmapConstants.MINIMUM_TILT,
9
to = NbmapConstants.MAXIMUM_TILT) double tilt)
10
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds,
11
@NonNull @Size(value = 4) int[] padding,
12
@FloatRange(from = NbmapConstants.MINIMUM_DIRECTION,
13
to = NbmapConstants.MAXIMUM_DIRECTION) double bearing,
14
@FloatRange(from = NbmapConstants.MINIMUM_TILT,
15
to = NbmapConstants.MAXIMUM_TILT) double tilt)
16
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry)
17
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
18
@NonNull @Size(value = 4) int[] padding)
19
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
20
@FloatRange(from = NbmapConstants.MINIMUM_DIRECTION,
21
to = NbmapConstants.MAXIMUM_DIRECTION) double bearing,
22
@FloatRange(from = NbmapConstants.MINIMUM_TILT,
23
to = NbmapConstants.MAXIMUM_TILT) double tilt)
24
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
25
@NonNull @Size(value = 4) int[] padding,
26
@FloatRange(from = NbmapConstants.MINIMUM_DIRECTION,
27
to = NbmapConstants.MAXIMUM_DIRECTION) double bearing,
28
@FloatRange(from = NbmapConstants.MINIMUM_TILT,
29
to = NbmapConstants.MAXIMUM_TILT) double tilt)
30
public void addOnCameraIdleListener(@NonNull OnCameraIdleListener listener)
31
public void removeOnCameraIdleListener(@NonNull OnCameraIdleListener listener)
32
public void addOnCameraMoveCancelListener(@NonNull OnCameraMoveCanceledListener listener)
33
public void removeOnCameraMoveCancelListener(@NonNull OnCameraMoveCanceledListener listener)
34
public void addOnCameraMoveStartedListener(@NonNull OnCameraMoveStartedListener listener)
35
public void removeOnCameraMoveStartedListener(@NonNull OnCameraMoveStartedListener listener)
36
public void addOnCameraMoveListener(@NonNull OnCameraMoveListener listener)
37
public void removeOnCameraMoveListener(@NonNull OnCameraMoveListener listener)

Annotations management

These are the functions provided by an annotations management system in a mapping application. The functions add a marker, polyline, or polygon to the map. The functions update a marker, polyline, or polygon that is already on the map. The functions remove a marker, polyline, or polygon, or remove all annotations from the map. The functions get annotations, markers, polylines, and polygons that are on the map.

1
public Marker addMarker(@NonNull LatLng position)
2
public Marker addMarker(@NonNull MarkerOptions markerOptions)
3
public Marker addMarker(@NonNull BaseMarkerOptions markerOptions)
4
public List<Marker> addMarkers(@NonNull List<? extends
5
BaseMarkerOptions> markerOptionsList)
6
public void updateMarker(@NonNull Marker updatedMarker)
7
public Polyline addPolyline(@NonNull LatLng origin, @NonNull LatLng dest, int color)
8
public Polyline addPolyline(@NonNull LatLng origin, @NonNull LatLng dest, String color)
9
public Polyline addPolyline(@NonNull List<LatLng> points, int color)
10
public Polyline addPolyline(@NonNull List<LatLng> points, String color)
11
public Polyline addPolyline(@NonNull PolylineOptions polylineOptions)
12
public List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList)
13
public void updatePolyline(@NonNull Polyline polyline)
14
public Polygon addPolygon(@NonNull List<LatLng> points, int color)
15
public Polygon addPolygon(@NonNull List<LatLng> points, String color)
16
public Polygon addPolygon(@NonNull PolygonOptions polygonOptions)
17
public List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList)
18
public void updatePolygon(@NonNull Polygon polygon)
19
public void removeMarker(@NonNull Marker marker)
20
public void removePolyline(@NonNull Polyline polyline)
21
public void removePolygon(@NonNull Polygon polygon)
22
public void removeAnnotation(@NonNull Annotation annotation)
23
public void removeAnnotation(long id)
24
public void removeAnnotations(@NonNull List<? extends Annotation> annotationList)
25
public void removeAnnotations()
26
public void clear()
27
public Annotation getAnnotation(long id)
28
public List<Annotation> getAnnotations()
29
public List<Marker> getMarkers()
30
public List<Polygon> getPolygons()
31
public List<Polyline> getPolylines()
32
public void setOnMarkerClickListener(@Nullable OnMarkerClickListener listener)
33
public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener)
34
public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener)
35
public void selectMarker(@NonNull Marker marker)
36
public void deselectMarkers()
37
public void deselectMarker(@NonNull Marker marker)
38
public List<Marker> getSelectedMarkers()

The setOnMarkerClickListener, setOnPolygonClickListener, and setOnPolylineClickListener functions allow setting listeners for clicks on markers, polylines, or polygons. The selectMarker and deselectMarker functions allow for selecting and deselecting markers. The getSelectedMarkers function returns the list of selected markers.

For more details of annotations, please refer to Markers and Annotations.

Manage gesture listeners

These are methods for adding and removing listeners for different types of gestures in an application.

1
public void addOnFlingListener(@NonNull OnFlingListener listener)
2
public void removeOnFlingListener(@NonNull OnFlingListener listener)
3
public void addOnMoveListener(@NonNull OnMoveListener listener)
4
public void removeOnMoveListener(@NonNull OnMoveListener listener)
5
public void addOnRotateListener(@NonNull OnRotateListener listener)
6
public void removeOnRotateListener(@NonNull OnRotateListener listener)
7
public void addOnScaleListener(@NonNull OnScaleListener listener)
8
public void removeOnScaleListener(@NonNull OnScaleListener listener)
9
public void addOnShoveListener(@NonNull OnShoveListener listener)
10
public void removeOnShoveListener(@NonNull OnShoveListener listener)
11
public void addOnMapClickListener(@NonNull OnMapClickListener listener)
12
public void removeOnMapClickListener(@NonNull OnMapClickListener listener)
13
public void addOnMapLongClickListener(@NonNull OnMapLongClickListener listener)

Available listeners:

1
OnFlingListener
2
OnMoveListener
3
OnRotateListener
4
OnScaleListener
5
OnShoveListener
6
OnCameraMoveStartedListener
7
OnCameraMoveListener
8
OnCameraMoveCanceledListener
9
OnCameraIdleListener
10
OnCompassAnimationListener
11
OnFpsChangedListener
12
OnGesturesManagerInteractionListener
13
OnMapClickListener
14
OnMapLongClickListener
15
OnMarkerClickListener
16
OnPolygonClickListener
17
OnPolylineClickListener
18
OnInfoWindowClickListener
19
OnInfoWindowLongClickListener
20
OnInfoWindowCloseListener
21
InfoWindowAdapter
22
CancelableCallback
23
SnapshotReadyCallback
24
OnDeveloperAnimationListener

For more details of gestures, please refer to UI Settings and Gestures.

Manage InfoWindow

These methods are for managing an InfoWindow in a map application. An InfoWindow is a pop-up window that provides information about a specific location or feature on a map.

1
public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener)
2
public OnInfoWindowClickListener getOnInfoWindowClickListener()
3
public void setOnInfoWindowLongClickListener(@Nullable OnInfoWindowLongClickListener)
4
public OnInfoWindowLongClickListener getOnInfoWindowLongClickListener()
5
public void setOnInfoWindowCloseListener(@Nullable OnInfoWindowCloseListener listener)
6
public OnInfoWindowCloseListener getOnInfoWindowCloseListener()
  • setOnInfoWindowClickListener: sets a listener to receive notifications when an InfoWindow is clicked.
  • getOnInfoWindowClickListener: returns the current InfoWindow click listener.
  • setOnInfoWindowLongClickListener: sets a listener to receive notifications when an InfoWindow is long-clicked.
  • getOnInfoWindowLongClickListener: returns the current InfoWindow long-click listener.
  • setOnInfoWindowCloseListener: sets a listener to receive notifications when an InfoWindow is closed.
  • getOnInfoWindowCloseListener: returns the current InfoWindow close listener.

Query rendered features

These methods are for querying the features that have been rendered on a map. A feature is a geometric shape (such as a point, line, or polygon) that represents a real-world object or location.

The methods take the following parameters:

  • coordinates: the location to query, either a point or a rectangle
  • filter: an optional expression used to filter the features based on their properties
  • layerIds: an optional list of layer IDs to restrict the query to

The methods return a list of Feature objects that have been rendered on the map and match the specified criteria.

1
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates, @Nullable String... layerIds)
2
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
3
@Nullable Expression filter,
4
@Nullable String... layerIds)
5
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates, @Nullable String... layerIds)
6
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
7
@Nullable Expression filter,
8
@Nullable String... layerIds)

The first two methods query features based on a point location. The second two methods query features based on a rectangular area. The difference between the two sets of methods is whether a filter expression is specified or not. If a filter is specified, only features that match the filter criteria will be returned. If no filter is specified, all features that have been rendered within the specified location will be returned.

Obtain reference of UiSettings

This method is for obtaining a reference to the UiSettings object associated with a map. The UiSettings object provides control over various user interface elements of the map, such as the zoom controls, the compass, and the my-location button.

1
public UiSettings getUiSettings()

By calling getUiSettings(), you can access the UiSettings object and use its methods to modify the behavior and appearance of the map's user interface elements.

For more details of UiSettings please refer to UI Settings and Gestures.

© 2024 NextBillion.ai all rights reserved.