30

I just updated google play services to rev 22 and the LocationClient class appears to be missing. What is going on?

Sam
  • 7,252
  • 16
  • 46
  • 65
ThanosFisherman
  • 5,626
  • 12
  • 38
  • 63
  • 5
    `LocationClient` has been deprecated since the summer, and apparently they now got rid of it entirely. There's a new API for it, using `GoogleApiClient`. See https://github.com/commonsguy/cw-omnibus/tree/master/Location/FusedNew for a sample app. – CommonsWare Dec 08 '14 at 19:56
  • Thanks for the fast response! Is there any documentation on how to use the fused location with this new API? I had no idea so now my app is now broken – ThanosFisherman Dec 08 '14 at 19:58
  • 1
    The documentation was pretty much non-existent when I last looked. I had to cobble together my sample app (and my book chapter update that uses it) from miscellaneous sources, including other questions here on Stack Overflow. Then again, I haven't looked for docs in a while, so it is possible that they published a tutorial or something when I wasn't looking. :-) – CommonsWare Dec 08 '14 at 20:00
  • 7
    The official training guide at https://developer.android.com/training/location/retrieve-current.html sill uses LocationClient – Price Dec 08 '14 at 20:05
  • Thank you @CommonsWare I will have a look at your github example and do a research to find my way around on this new Api. I will post back asap. Seems that location listeners have also changed – ThanosFisherman Dec 08 '14 at 20:06
  • BTW, since you mention that you're using Eclipse, you really should start planning on moving to Android Studio, as work on Eclipse has officially ended as of today. Being on Android Studio would actually help you here, as you could more readily continue using an older Play Services library until such time as you were ready to move over to the new API. While migrating from Eclipse to Android Studio is not "a walk in the park", versioned dependencies help with backwards-compatibility issues like yours. – CommonsWare Dec 08 '14 at 20:11
  • @CommonsWare yeah that's true. Versioning dependencies is easy when using gradle. The thing is I have a couple of apps that are using NDK and last time I checked, Android studio didn't support NDK stuff. But I'd rather move to intellij cause I have java SE projects that rely on some android apps (i.e LibGDX games) but no ndk there either. Considering those, I decided to stick with eclipse for some more time since Eclipse team is planning to update and maintain ADT-gradle-ndk via a project called Andmore from now on – ThanosFisherman Dec 08 '14 at 20:28
  • "last time I checked, Android studio didn't support NDK stuff" -- it does, whether through using the standard NDK build tools (not documented but recipes are available) or for simpler scenarios directly through Gradle (bypassing makefiles). – CommonsWare Dec 08 '14 at 20:41
  • "or for simpler scenarios directly through Gradle (bypassing makefiles)" -- Oh that's even more comfortable then but seems like big learning curve to achieve all that migration? I don't know much about gradle either but I'm going to give it a try soon thanks – ThanosFisherman Dec 08 '14 at 20:56
  • I didn't realize `LocationClient` was deprecated either. The code example from @CommonsWare works AFAIK. Adding to @CommonsWare's sample/code, the connection/disconnection/checking connection state (`isConnected()` and `isConnecting()`) is done through `GoogleApiClient`. For continuous location requests `LocationRequest`, use `LocationServices.FusedLocationApi` and the method calls are similar except you have to pass in your `GoogleApiClient` instance with them. But its very similar to the old `LocationClient`. I'll continue testing this further – Ani Fichadia Dec 09 '14 at 04:46
  • possible duplicate of [Android play services 6.5: LocationClient is missing](http://stackoverflow.com/questions/27372638/android-play-services-6-5-locationclient-is-missing) – ben75 Dec 18 '14 at 22:27

1 Answers1

71

Building on what @CommnsWare said, here are steps to migrate to Fused api.

Step 1: Get an instance of GoogleApiClient instead of LocationClient.

The ConnectionCallback (mConnectionCallbacks, mOnConnectionFailedListener in example below) needs slight modification but that should be trivial.

googleApiClient = new GoogleApiClient.Builder(this)
        .addApi(LocationServices.API)
        .addConnectionCallbacks(mConnectionCallbacks)
        .addOnConnectionFailedListener(mOnConnectionFailedListener)
        .build();

Step 2: Update connect and disconnect calls.

Replace the locationClient.connect() with googleApiClient.connect() and locationClient.disconnect() with googleApiClient.disconnect().

Step 3: Use LocationServices.FusedLocationApi to send your requests. e.g.

LocationServices.FusedLocationApi.getLastLocation(googleApiClient)
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, mLocationListener);

Hope this helps!

Gelldur
  • 11,187
  • 7
  • 57
  • 68
Parag Sarda
  • 1,576
  • 1
  • 13
  • 5
  • 3
    Yeap that's the steps I just figured them out using @CommonsWare sample too. Also for the interfaces you just need to replace the old ones with GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener Plus LocationListener remains the same only there is no onDisconnect method anymore – ThanosFisherman Dec 09 '14 at 15:42
  • How about requesting location updates at certain intervals? Is that still supported in GoogleApiClient? – IgorGanapolsky Jan 23 '15 at 16:09