I'm using the Mapbox SDK and I want to move and zoom the map to the current location. If I enable the location layer, I get the dot in the correct spot. However my location engine listener isn't being called so I can't move the camera.
In onCreateView
I start a connection with a GoogleApiClient
. Once that's connected I use it to check the location settings to see if they're turned on (after checking for permission for location). If that succeeds, I do this:
if (locationEngine == null) {
locationEngine = new LocationSource(getActivity());
locationEngine.requestLocationUpdates();
}
Location location = locationEngine.getLastLocation(); // This returns null
onLocationChanged(location); // This moves the camera if a location is passed in
locationEngine.addLocationEngineListener(locationEngineListener);
// This works, the location layer functions properly
getMap(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapboxMap.setMyLocationEnabled(true);
}
});
Here's what locationEngineListener
does:
private class Listener implements LocationEngineListener {
@Override
public void onConnected() {
// No action needed here.
}
@Override
public void onLocationChanged(Location location) {
CurrentLocationMap.this.onLocationChanged(location);
}
}
The problem is onLocationChanged
is never called.