I am recycling the code provided to check that the user's device has Google Play services on it before acquiring location data from http://developer.android.com/training/location/retrieve-current.html. When copy-pasting it into my IDE, Eclipse correctly points out errors in lines, because "connectionResult" has never been defined, nor is "getSupportFragmentManager"
int errorCode = connectionResult.getErrorCode();
and
errorFragment.show(getSupportFragmentManager(),
"Location Updates");
Should I just create a variable above called ConnectionResult connectionResult to fix the issue? I am not sure about how to correct the second.
Additionally, the line
mLocationClient = new LocationClient(this, this, this);
from further along the page suggests putting in the MainActivity class which does not satisfy the LocationClient constructor, evoking another error.
Update: Another issue with the tutorial. Hi all, the tutorial references the class LocationResult which it has not created here: http://developer.android.com/training/location/receive-location-updates.html. How/where am I supposed to define this?
The tutorial is misleading. If you want to check google play services exist do the following.
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (errorCode != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(errorCode, this, 0).show();
}
This will automatically show an appropriate error dialog if it doesn't in exist.
To your second problem. The remainder of the tutorial does need to be followed. You do need to implement GooglePlayServicesClient.ConnectionCallbacks
and GooglePlayServicesClient.OnConnectionFailedListener
if you want to create the the locationclient using new LocationClient(this, this, this);
Note: do not try to use the locationclient until after the onConnected
method is called in your callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With