HERE Android SDK Developer's Guide

Basic Positioning

The HERE Android SDK provides the following interfaces for users to retrieve location updates and to display their current location on a map:
  • PositioningManager
  • OnPositionChangedListener
  • PositionIndicator

PositioningManager Class

A PositioningManager class provides information related to the device's geographical location, like the current position and the average speed. Applications can register to receive position updates using one of the positioning mechanisms described in the LocationMethod:

  • GPS - positioning using the real GPS available on the device.
  • GPS_NETWORK - positioning is provided using a wireless network or the real GPS available on the device
  • NETWORK - positioning using a wireless network.
Note: See Advanced Positioning by HERE for more information about additional Location Method types.

The current status of a particular location method is represented by the LocationStatus value returned from the PositioningManager.getLocationStatus(LocationMethod) method.

PositioningManager can be accessed by calling PositioningManager.getInstance(). An application can start receiving real time positioning updates by calling PositioningManager.start(LocationMethod) with one of the location methods listed above and can stop the positioning updates by calling PositioningManager.stop(). While position updates are being received, an application can retrieve the current position of the client device via the PositioningManager.getPosition() method.

OnPositionChangedListener Interface

In addition to the PositioningManager's getPosition() method, applications can subscribe to position update notifications from the PositioningManager through the PositioningManager.OnPositionChangedListener interface. To add or remove OnPositionChangedListener, applications can use the following methods:

PositioningManager.addListener(WeakReference<OnPositionChangedListener>)
PositioningManager.removeListener(OnPositionChangedListener)

The positioning manager enhances your application with the current position of the user's device. The registration of the positioning listener should be performed after the MapFragment, MapView, or MapEngine is initialized as described in the following code snippet.

// Define positioning listener
private OnPositionChangedListener positionListener = new
  OnPositionChangedListener() {

    public void onPositionUpdated(LocationMethod method,
        GeoPosition position, boolean isMapMatched) {
      // set the center only when the app is in the foreground
      // to reduce CPU consumption
      if (!paused) {
        map.setCenter(position.getCoordinate(),
            Map.Animation.NONE);
      }
    }

    public void onPositionFixChanged(LocationMethod method,
        LocationStatus status) {
    }
};

// Register positioning listener
PositioningManager.getInstance().addListener(
  new WeakReference<OnPositionChangedListener>(positionListener));
...

In order to avoid unnecessary position updates while the activity is in the background, you need to start or stop the PositioningManager within your activity's onResume() and onPause() methods.

// Set this to PositioningManager.getInstance() upon Engine Initialization
private PositioningManager posManager;
...

// Resume positioning listener on wake up
public void onResume() {
  super.onResume();
  paused = false;
  if (posManager != null) {
    posManager.start(
        PositioningManager.LocationMethod.GPS_NETWORK);
  }
}

// To pause positioning listener
public void onPause() {
  if (posManager != null) {
    posManager.stop();
  }
  super.onPause();
  paused = true;
}

// To remove the positioning listener
public void onDestroy() {
  if (posManager != null) {
    // Cleanup
    posManager.removeListener(
        positionListener);
  }
  map = null;
  super.onDestroy();
}

PositionIndicator Class

PositionIndicator is a special map marker object that allows the current client device position to be shown on a map. Every HERE SDK Map object has an integrated position indicator, set to invisible, by default. The indicator can be retrieved and set to visible by calling MapFragments.getPositionIndicator() and PositionIndicator.setVisible(), as follows:

// Display position indicator
mapFragment.getPositionIndicator().setVisible(true);

By default, the position indicator is rendered as a marker surrounded by a circle, the diameter of which illustrates the accuracy of the indicated position. You can change this marker by calling PositionIndicator.setMarker(Image).

Figure 1. A PositionIndicator
Note: For the position indicator to stay in the center of the map and illustrate real-time updates of the device's position, it is necessary to update the map's center whenever a new location update is received.
Note: PositionIndicator only works if the application has started the PositioningManager.

Position Simulation and Creating Position Logs

You can use PositionSimulator to simulate device position by injecting locations into the Android LocationManager. Locations are read from GPX log files. After calling PositionSimulator.startPlayback(String), the positions in the log file are processed until the end of the log is reached or stopPlayback() is called.

You can also use the HERE SDK to create the GPX logs that can be replayed by PositionSimulator. To do this, call setLogType(EnumSet<LogType>) in PositioningManager to include LogType.DATA_SOURCE. GPX logs are written to a "gpx" sub-directory of your appication's data directory — for example, "/sdcard/Android/data/com.companyName.appName/files/gpx/". To disable logging, call setLogType(EnumSet.noneOf(LogType.class)).

Note: This feature is only intended for debugging purposes. Do not use Position Logging in a production application.
Note: PositionSimulator does not support indoor positioning.

You cannot use this account to purchase a commercial plan on Developer Portal, as it is already associated to plans with different payment methods.

To purchase a commercial plan on Developer Portal, please register for or sign in with a different HERE Account.

Something took longer than expected.

The project should be available soon under your projects page.

Sorry, our services are not available in this region.

Something seems to have gone wrong. Please try again later.

We've detected that your account is set to Australian Dollars (AUD).
Unfortunately, we do not offer checkouts in AUD anymore.
You can continue using your current plan as normal, but to subscribe to one of our new plans,
please register for a new HERE account or contact us for billing questions on selfservesupport@here.com.