(Android location) onConnected/onDisconnected reimplemented - still don't seem

to get to onLocationChanged though
This commit is contained in:
twinaphex 2013-12-20 21:49:43 +01:00
parent 1a20317cef
commit 0d94dd03f7

View File

@ -49,12 +49,16 @@ LocationListener
{
// Display the connection status
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
location_service_running = true;
// If already requested, start periodic updates
if (mUpdatesRequested)
{
mLocationClient.requestLocationUpdates(mLocationRequest,
(com.google.android.gms.location.LocationListener) this);
}
else
// Get last known location
mCurrentLocation = mLocationClient.getLastLocation();
}
/*
@ -67,6 +71,19 @@ LocationListener
// Display the connection status
Toast.makeText(this, "Disconnected. Please re-connect.",
Toast.LENGTH_SHORT).show();
// If the client is connected
if (mLocationClient.isConnected())
{
/*
* Remove location updates for a listener.
* The current Activity is the listener, so
* the argument is "this".
*/
mLocationClient.removeLocationUpdates((com.google.android.gms.location.LocationListener) this);
}
location_service_running = false;
}
/*
@ -160,10 +177,6 @@ LocationListener
// Connect the client.
mLocationClient.connect();
// Get last known location
mCurrentLocation = mLocationClient.getLastLocation();
location_service_running = true;
}
/**
@ -183,24 +196,8 @@ LocationListener
if (!location_service_running)
return;
// If the client is connected
if (mLocationClient.isConnected())
{
/*
* Remove location updates for a listener.
* The current Activity is the listener, so
* the argument is "this".
*/
mLocationClient.removeLocationUpdates((com.google.android.gms.location.LocationListener) this);
}
if (location_service_running)
{
// Disconnecting the client invalidates it.
mLocationClient.disconnect();
}
location_service_running = false;
// Disconnecting the client invalidates it.
mLocationClient.disconnect();
}
/**
@ -252,6 +249,9 @@ LocationListener
@Override
public void onLocationChanged(Location location)
{
if (!location_service_running)
return;
locationChanged = true;
mCurrentLocation = location;