HERE SDK for Android (Starter Edition)

HERE Android SDK Developer's Guide

Objects and Interaction

You can select ViewObject objects by using a single tap gesture. To enable this in your code, create an OnGestureListener object and pass it to AndroidXMapFragment.getMapGesture().addOnGestureListener(OnGestureListener). When a single tap occurs, the listener receives the onTapEvent(PointF) callback, and if that event is not handled, then the listener receives the onMapObjectsSelected(List<ViewObject>) callback. The application can then define what to do with the selected ViewObject.

Types of ViewObject objects that are selectable are defined within the ViewObject.Type enumeration includes the following:

  • USER_OBJECT - an object the application adds to a map with a MapObject base class (MapPolygon for example).
  • UNKNOWN_OBJECT - a selectable map object that is neither USER_OBJECT

The ViewObject Abstract Class

The ViewObject abstract class represents the base implementation for all objects selectable on a MapView or AndroidXMapFragment. The AndroidXMapFragment features user-selectable objects.

Sub-classes of the ViewObject class include MapObject .

MapObject and Geo Objects

MapObject represents an abstract class for all map related objects that can be added on a Map. The subclasses of this abstract class include the following:

  • MapContainer
  • MapCircle
  • MapPolyline
  • MapPolygon
  • MapRoute
  • MapMarker

These objects can be created by calling the appropriate constructor methods. In some cases a geo object is required in the constructor. Geo objects (for example, GeoPolyline and GeoPolygon) are geographical data representations that act as models to MapObjects, which act as views. Unlike map objects, geo objects cannot be added directly to a Map. For more information on geo objects and creating map objects see the API Reference.

The following code snippet demonstrates how to create a MapPolyline and a GeoPolyline object:

List<GeoCoordinate> testPoints = new ArrayList<GeoCoordinate>();
testPoints.add(new GeoCoordinate(49.163, -123.137766, 10));
testPoints.add(new GeoCoordinate(59.163, -123.137766, 10));
testPoints.add(new GeoCoordinate(60.163, -123.137766, 10));
GeoPolyline polyline = new GeoPolyline(testPoints);
MapPolyline mapPolyline = new MapPolyline(polyline);

To add a MapObject to the map, use Map.addMapObject(MapObject) or Map.addMapObjects(List<MapObject>).


You can use MapContainer as a container for other MapObject instances. Map containers determine the stacking order of objects displayed on a map. To add a map object, call the MapContainer.addMapObject(MapObject) method.

Note: MapRoute and MapContainer cannot be added to a MapContainer.


A MapCircle represents a type of MapObject in the shape of a circle with an assigned radius distance and a GeoCoordinate center. It can be created by calling the constructor MapCircle(double radius, GeoCoordinate center).

Figure 1. A MapCircle object


A MapPolyline is a MapObject in the shape of a polyline with anchor points at any number of GeoCoordinate points. It can be created via a GeoPolyline object, which can be created by calling the GeoPolyline(List<GeoCoordinate> points) constructor.

Note: A MapPolyline or MapPolygon can only contain up to 65536 vertices.
Figure 2. A MapPolyline object


A MapPolygon is a MapObject in the shape of a polygon. In contrast to a MapPolyline it is assumed that the last coordinate in the line path is connected to the first coordinate thereby constructing an enclosed geometry. A MapPolygon may have separate border and fill colors. To create a MapPolygon, use the constructor MapPolygon(GeoPolygon polygon). A GeoPolygon can be created by calling GeoPolygon(List<GeoCoordinate> points).

Figure 3. A MapPolygon object


A MapRoute is a MapObject that displays a calculated route on a map. For more information on MapRoute see Routing.


A MapMarker is a MapObject that displays an icon at a geographical position on a map. You can create a MapMarker with your own custom icon by calling MapMarker(GeoCoordinate, Image).

Figure 4. A MapMarker object

MapMarker instances are always placed on top of other map objects. Refer to the diagram below for more information about z-index ordering for multiple map markers.

Figure 5. MapMarker order

You can set MapMarker to be draggable by using the MapMarker.setDraggable(true) method. To listen to drag events, such as marker position changes, use MapMarker.OnDragListener.

User Interactions with MapObject

This section provides an example of handling MapObject tap events. In the following code:

  • addMapObject() adds the object on the Map.
  • List<ViewObject> holds the objects that have been selected in this tap event. By looping through this list of objects your code can find the MapObject that should respond to this tap event.
Note: The onMapObjectsSelected(List) callback is triggered after the onTapEvent(PointF) callback. For more information on this refer to Map Gestures.

// Create a custom marker image myImage =

try {
} catch (IOException e) {

// Create the MapMarker
MapMarker myMapMarker =
  new MapMarker(new GeoCoordinate(LAT, LNG), myImage);



// Create a gesture listener and add it to the AndroidXMapFragment
MapGesture.OnGestureListener listener =
  new MapGesture.OnGestureListener.OnGestureListenerAdapter() {
    public boolean onMapObjectsSelected(List<ViewObject> objects) {
      for (ViewObject viewObj : objects) {
        if (viewObj.getBaseType() == ViewObject.Type.USER_OBJECT) {
          if (((MapObject)viewObj).getType() == MapObject.Type.MARKER) {
            // At this point we have the originally added
            // map marker, so we can do something with it
            // (like change the visibility, or more
            // marker-specific actions)
      // return false to allow the map to handle this callback also
      return false;