0

I am trying to get the current location of the user using Mapbox SDK for Android. After reviewing the tutorials and everything else out there available i concluded that all of the techniques that are shown include deprecated methods.

I tried to use the following technique since may be is my only shot but i run to an error which i cannot solve: error: cannot access LocationListener class file for com.google.android.gms.location.LocationListener not found.

Here is part of my code that is producing the error:

@Override
protected void onCreate(Bundle savedInstanceState) {
    context = this;
    super.onCreate(savedInstanceState);
    Mapbox.getInstance(this, API_KEY);

    setContentView(R.layout.activity_map_view_test);


    locationEngine = GoogleLocationEngine.getLocationEngine(context);

    myLocation = locationEngine.getLastLocation();


    mapView = (MapView) findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(final MapboxMap mapboxMap) {
            mapboxMap.addMarker(new MarkerOptions()
                    .position(new LatLng(myLocation.getLatitude(),myLocation.getLongitude()))
                    .title("My Location")
                    .snippet("Illinois")
            );

            mapboxMap.setLatLng(mapboxMap.getMarkers().get(0).getPosition());
        }
    });
}

Does anyone have some bright ideas? Any help is apreciated.

Best regards,

Dimitar Georgiev

  • I put my Mapbox project on hold months ago rather than try to continue sorting through their location system they deprecated but didn't seem to have a ready replacement for. If you've been watching the releases, however, v0.5 of the [`LocationLayer` plugin](https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer) was released this week with the claim that it ["offers parity with the old MyLocationView API and should be the preferred tool for displaying user's location going forward"](https://github.com/mapbox/mapbox-gl-native/pull/11351#issue-172216213). Try it maybe? – Matt Apr 06 '18 at 08:23
  • @HEATH3N Thank you very much for the response. I am also trying to figure it out but for not i have no success. I will try to use the LocationLayer but I am almost to the point of giving up and try use some other opensource map provider. – Dimitar Georgiev Apr 09 '18 at 15:15
  • @DimitarGeorgiev from where you want to get the location form mapbox api or from google api? – Rahul Jun 21 '18 at 16:54
  • From the Mapbox API. The whole idea was to make a layer over the normal map with a picture si it can look like indoor map. But apparently this willnot happen so i decided skip this functionality for now. – Dimitar Georgiev Jun 26 '18 at 08:07

2 Answers2

0

Please check your Proguard Rules if you enabled shrink resources in Gradle

Amit Kumar
  • 547
  • 3
  • 10
-1

Do you really need to use the Google LocationEngine? I have worked with the LocationEngine provided by the MapBox SDK and it has resulted very good to work with. You can try importing:

com.mapbox.android.core.location.LocationEngine;
Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69