GPSMapLocationProvider Class (Android only)

Note

Bing Maps SDK for Android and iOS retirement

Bing Maps SDK for Android and iOS is deprecated and will be retired. Free (Basic) account customers can continue to use Bing Maps SDK for Android and iOS until June 30th, 2025. Enterprise account customers can continue to use Bing Maps SDK for Android and iOS until June 30th, 2028. To avoid service disruptions, all implementations using Bing Maps SDK for Android and iOS will need to be updated to use Azure Maps Web SDK by the retirement date that applies to your Bing Maps for Enterprise account type.

Azure Maps is Microsoft's next-generation maps and geospatial services for developers. Azure Maps has many of the same features as Bing Maps for Enterprise, and more. To get started with Azure Maps, create a free Azure subscription and an Azure Maps account. For more information about azure Maps, see Azure Maps Documentation. For migration guidance, see Bing Maps Migration Overview.

A location provider which uses GPS location services.

The benefit of using this location provider is that it works in all countries/regions as it comes with all Android phones. You also don't have to pull in an extra module to use this provider. The downside to using this provider is that it is not battery efficient. Also, you have to choose one provider to retrieve signals from (such as network or GPS) instead of having them all work together for one signal.

class GPSMapLocationProvider extends MapLocationProvider

Constructor

In order to construct a GPSMapLocationProvider, use GPSMapLocationProvider.Builder to optionally set your own settings and then call build() to construct an instance.

public static class Builder {
  Builder(Context context);

  Builder setMinTime(long minTime);

  Builder setDesiredProviders(ArrayList<String> desiredProviders);

  Builder setSensorSamplingPeriod(int sensorSamplingPeriod);

  /**
   * Call this to show last location available on launch if it exists.
   */
  Builder useLastKnownLocationOnLaunch();

  /**
   * Helps user set settings to be used in navigation mode.
   * Sets minTime as 1 second and desiredProviders as GPS_PROVIDER,
   * NETWORK_PROVIDER, and PASSIVE_PROVIDER in that order,
   * and sensorSamplingPeriod as 20 ms.
   */
  Builder setNavigationSettings();

  GPSMapLocationProvider build();
}

Example:

new GPSMapLocationProvider.Builder(getApplicationContext())
      .setDesiredProviders(new ArrayList<>(Arrays.asList(LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER)))
      .setMinTime(TimeUnit.SECONDS.toMillis(0))
      .build();

Properties

MinTime

Represents the minimum time interval between location updates in milliseconds. Default minTime is 5000.

If set is called before location retrieval started, setting will be saved for when location retrieval starts. If set is called after location retrieval started, it will restart with the new setting.

void setMinTime(long minTime)
long getMinTime()

DesiredProviders

Represents the desired providers to be used in the order you want them to be tried. If location tracking can not be started with the desiredProviders, the default providers will be used instead. Default desiredProviders is an array containing LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER and LocationManager.PASSIVE_PROVIDER in that order.

If set is called before location retrieval started, setting will be saved for when location retrieval starts. If set is called after location retrieval started, it will restart with the new setting.

void setDesiredProviders(ArrayList<String> desiredProviders)
ArrayList<String> getDesiredProviders()

SensorSamplingPeriod

See MapLocationProvider

See Also