cannot resolve symbol 'LocationServices'

柔情痞子 提交于 2019-12-22 01:34:05

问题


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:

Thanks in advance


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/42890669/cannot-resolve-symbol-locationservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!