25

I am trying to build an android app using android studio that uses the userlocation. I am trying to import the google play services LocationServices api, but it says it can't resolve symbol 'LocationServices'. I tried searching for an answer but I can't figure out what the problem is.

here is a picture of my error and code: code and error

new error

third error (yes I'm a rookie)

Thanks in advance

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jord Adema
  • 271
  • 1
  • 3
  • 9

2 Answers2

50

You need to import:

import com.google.android.gms.location.LocationServices;

And in build.gradle:

implementation 'com.google.android.gms:play-services-location:11.0.2'

you class must implement:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,
    LocationListener,
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener { ...}

You need to OverWrite this methods:

 @Override
    public void onConnected(Bundle bundle) {

    }


    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }

    @Override
    public void onLocationChanged(Location location) {

    }

Here is a detail Implementation

Mike Yang
  • 2,581
  • 3
  • 24
  • 27
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • sorry to ask this much, but this gets me a new error. I edited the post again. I you didn't found out yet, im quite a rookie – Jord Adema Mar 19 '17 at 19:09
  • never mind, fixed the issue by putting abstract before the 'public class....'. Thanks so much for helping me out – Jord Adema Mar 19 '17 at 19:13
  • Not needed to put abstract...you need to overwrite the added methods... – rafsanahmad007 Mar 19 '17 at 19:16
  • In android Studio put cursor over the red line: and Press `ALT+ENTER` it will shows the error resolve technique: like...override method , import class etc suggestion will be provided.. – rafsanahmad007 Mar 19 '17 at 19:19
  • thanks, I'll study that guide and if I encounter any unsolvable problems I'll ask again. Thanks again for your quick responses. – Jord Adema Mar 19 '17 at 19:23
  • Great this worked for me. Just adding the location service into Gradle – Tony Merritt May 04 '17 at 12:03
4

Looking at this 7 months after it was posted and got me out of a jam.

At the moment of writing, you have to update the build.gradle(Module: app) to compile 'com.google.android.gms:play-services-location:11.4.2' https://developers.google.com/android/guides/setup

Your post helped me a lot and I hope this addition also helps others looking at this post in the future.

Jamie Coenen
  • 75
  • 1
  • 10