My onLocationChanged is not called at all. Any ideas why? I have all the permissions. Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate_me);
createLocationRequest();
buildGoogleApiClient();
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
MapFragment mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
mapFragment.setRetainInstance(true);
}
@Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
@Override
public void onConnected(Bundle bundle) {
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
displayMessage("message","my position changed");
}
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
private void displayMessage(String title, String message) {
//displaying a message
}
@Override
protected void onPause() {
super.onPause();
stopLocationUpdates();
}
protected void stopLocationUpdates() {
LocationServices.FusedLocationApi.removeLocationUpdates(
mGoogleApiClient, this);
}
@Override
public void onResume() {
super.onResume();
if (mGoogleApiClient.isConnected() && !mRequestingLocationUpdates) {
startLocationUpdates();
}
}
I followed android tutorial and it all seems to be the same, but onLocationChanged isn't being called (in this case message is not displayed). Btw, it seemed to have worked about 3 weeks ago, I don't know what changed.