HERE SDK for Android (Premium Edition)

SDK for Android Developer's Guide

Positioning by Google Location Services

In addition to the basic platform positioning SDK for Android provides positioning by means of Google Location Services.

Google Location Services information

To use positioning by Google Location Services, Google Play Services must be available on the target devices. Please refer to developers.google.com for more information.

Using Google Location Services

To start using Google Location Services in the Android applications, perform the following steps:

  1. Add the dependency on the Google Location Services in your application
  2. Add the required Android permissions to your application
  3. Set the positioning data source to Google Location Services and start the Positioning Manager
  4. Receive and handle location updates

In detail, the following actions need to be taken:

1) Add the dependency on the Google Location Services

Add a new build rule under dependencies for the latest version of Google Location Services in build.gradle:

dependencies {
  (...)
  implementation 'com.google.android.gms:play-services-location:17.0.0'
  (...)
}

2) Add the Android permissions to your application

Update AndroidManifest.xml with the following permissions:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Note: If your application uses Android target SDK version level 23 or above, you must add code to request permissions at runtime. For more detailed instructions and example code, see Requesting Android Permissions.

3) Change the positioning data source and start PositioningManager

After completion of the previous configuration steps, change the Positioning Manager data source to Google Location Services and start the Positioning Manager with the suitable location method:
m_googleLocationDataSource = LocationDataSourceGoogleServices.getInstance();
if (m_googleLocationDataSource != null) {
  PositioningManager pm = PositioningManager.getInstance();

  pm.setDataSource(m_googleLocationDataSource);
  pm.addListener(new WeakReference<PositioningManager.OnPositionChangedListener>(this));
  if (pm.start(PositioningManager.LocationMethod.GPS_NETWORK)) {
    // Position updates started successfully.
  }
}

4) Receive and handle location updates

The location updates are handled by onPositionUpdated() (when the device location changes) and onPositionFixChanged() (when location method changes) methods from OnPositionChangedListener:

@Override
public void onPositionUpdated(final PositioningManager.LocationMethod locationMethod, final GeoPosition geoPosition, final boolean mapMatched) {
  // new position update received
}

@Override
public void onPositionFixChanged(PositioningManager.LocationMethod locationMethod, PositioningManager.LocationStatus locationStatus) {
  // positioning method changed
}
Note:
  • PositioningManager.OnPositionChangedListener represents an interface for the position update listeners.
  • GeoPosition carries GeoCoordinate that contains the device WGS84 Latitude/Longitude coordinates and altitude with double precision. In addition, GeoPosition carries location uncertainty estimate as well as speed and heading information.