maplibre / maplibre-navigation-android

Maplibre Navigation SDK for Android
MIT License
87 stars 45 forks source link

How To: Force to Android GPS and Network Providers (no gms) #48

Closed moiatto closed 1 year ago

moiatto commented 1 year ago

How can I force LocationEngineProvider to use Android GPS and Network Providers instead Google's Fused Location Providers ?

Short story:

The problem start from the last line:

MapboxNavigationOptions options = MapboxNavigationOptions.builder()
                .isDebugLoggingEnabled(true)
                .build();
navigation = new MapboxNavigation(requireContext(), options);
navigation.addNavigationEventListener(this);
navigation.addMilestoneEventListener(this);
navigation.setLocationEngine(LocationEngineProvider.getBestLocationEngine(requireContext()));

I have this dependencies in my app

implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.github.maplibre:maplibre-navigation-android:84e9f77a55' 
implementation 'org.maplibre.gl:android-sdk:9.6.0'    

The gms v21.0.1 is not compatible with maplibre-gl v9.6.0, throwing this error:

java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.FusedLocationProviderClient....

I have tried to update maplibre-gl to the last version v10.0.1, but there are 2 problems;

  1. I don't understand the documentation to obtain a valid LocationEngine to pass in navigation.setLocationEngine
  2. On run app I get errors about icons not found linked in the library file values.xml at pos: 9711:

    ....
    <style name="mapbox_LocationLayer">
        <item name="mapbox_foregroundDrawable">@drawable/mapbox_user_icon</item>
        <item name="mapbox_backgroundDrawable">@drawable/mapbox_user_stroke_icon</item>
        <item name="mapbox_bearingDrawable">@drawable/mapbox_user_bearing_icon</item>
        <item name="mapbox_gpsDrawable">@drawable/mapbox_user_puck_icon</item>
    
        <item name="mapbox_foregroundDrawableStale">@drawable/mapbox_user_icon_stale</item>
        <item name="mapbox_backgroundDrawableStale">@drawable/mapbox_user_stroke_icon</item>
    
        <item name="mapbox_accuracyAlpha">0.15</item>
        <item name="mapbox_accuracyColor">@color/mapbox_location_layer_blue</item>
    ....

    where can i find these icons?

So, the alternative is to use Android GPS and Network Providers instead of Google's Fused Location Providers.

boldtrn commented 1 year ago

This repo is now on v10.0.2, maybe you want to try again?

boldtrn commented 1 year ago

I will close this for now, as I haven't heard back. You can set the locationEngine when you init the MapboxNavigation class.