Skip to content

LocationEngineProvider provides incorrect 'best' LocationEngine #788

@codeversed

Description

@codeversed

When using an Android device that does not have Google Play Services installed, LocationEngineProvider obtains the wrong LocationEngine. If the application includes dependencies for com.google.android.gms.location.LocationServices, a false positive returns LocationEngine.Type.GOOGLE_PLAY_SERVICES.

Steps to reproduce

  1. Use a device that does not have Google Play Services (or the play store) installed. Example: DJI Crystal Sky
  2. Use the latest MapBox SDK's LocationEngineProvider to obtainBestLocationEngineAvailable()
  3. Observe the LocationEngine provided is LocationEngine.Type.GOOGLE_PLAY_SERVICES which can not be used if the device does not have Google Play Services installed

Expected behavior

The LocationEngineProvider should provide LocationEngine with LocationEngine.Type.ANDROID

Actual behavior

The LocationEngine provides LocationEngine.Type.GOOGLE_PLAY_SERVICES

Configuration

DJI Crystal Sky running (Android API level 22), no Play Services

mapbox-android-sdk:6.6.1
mapbox-android-plugin-locationlayer:0.11.0

My Workaround

private LocationEngine obtainBestLocationEngineAvailable(Context context) {
    if (PlayServicesUtils.checkPlayServices(context)) {
        return new LocationEngineProvider(context).obtainBestLocationEngineAvailable();
    } else {
        return new LocationEngineProvider(context)
                .obtainLocationEngineBy(LocationEngine.Type.ANDROID);
    }
}
/**
 * Check the device to make sure it has the Google Play Services APK. If
 * it doesn't, display a dialog that allows users to download the APK from
 * the Google Play Store or enable it in the device's system settings.
 */
public static boolean checkPlayServices(Context context) {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
    return resultCode == ConnectionResult.SUCCESS;
}

This will ensure that the device has Google Play Services, which is required for LocationEngine.Type.GOOGLE_PLAY_SERVICES aka Google's FusedLocationProvider

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions