Reputation: 201
I have a MapView
in a fragment, and I'm having two problems that I can't seem to find solutions for. I've searched but I don't see anyone else having these problems. For reference, I am mainly following this tutorial on the developer pages.
This is my fragment:
public class MapFragment extends Fragment
implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener
The first problem is here:
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(LocationServices.API)
.addConnectionCallbacks(this) //problem!
.addOnConnectionFailedListener(this) //problem!
.build();
Calling addConnectionCallbacks(this)
gives an error saying it cannot be applied to myPackageName.MapFragment
. I know you have to pass a GoogleApiClient.ConnectionCallbacks
listener here, but every example I see uses this
, and I'm not sure what to do. The same problem arises in addOnConnectionFailedListener
. In my fragment I have implemented all necessary methods, such as onLocationChanged()
.
The second problem is here:
@Override
public void onConnectionSuspended(int i)
{
Log.i(TAG_MAP_FRAGMENT, "GoogleApiClient connection has been suspended");
}
This gives an error message saying: Method does not override method from its superclass
. I've searched and I haven't been able to find anyone else with this problem. I'm not sure how to deal with it.
Anyone know how to fix these? Thank you for the help!
Upvotes: 1
Views: 2850
Reputation: 201
Instead of:
implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener
try:
implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
This resolves all three problems originally posted above. However, now the method onDisconnected()
is marked with an error method does not override method from superclass
.
The error is fixed when you use all four:
implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
This doesn't seem ideal, but it works, at least for now. If you stumble across this and you know of a better fix, please leave a reply.
Upvotes: 4