cannot resolve symbol 'LocationServices'

Jord Adema picture Jord Adema · Mar 19, 2017 · Viewed 26.2k times · Source

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

Answer

rafsanahmad007 picture rafsanahmad007 · Mar 19, 2017

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