2

I'm trying to use Fused Location API in order to get location in my app.

what I do is calling a LocationClient.connect() and then I look for location inside the onConnected method.

What I unexpectedly get is this:

IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

but I am inside the onConnected method! O_o

Even if I'm there I apparently am not connected to the service at all! What am I supposed to do then?

This is the code which provokes the error:

        Geocoder geoCoder = new Geocoder(this.getActivity(), Locale.getDefault());

        String locationCity = "";

        try {
            Location loc = locationclient.getLastLocation();
        ...

1 Answers1

0

call locationClient.connect() in onCreate() method.

and in onConnected() method add a check as below

if (locationclient != null && locationclient.isConnected()) {

locationclient.requestLocationUpdates(locationrequest, this);

}

Revathi
  • 172
  • 8