Can't find the class com.google.android.gms.location.LocationClient (android)

后端 未结 11 1743
离开以前
离开以前 2020-12-15 16:03

I have download a demo project from http://developer.android.com/training/location/retrieve-current.html, and I think I don\'t lost any steps; But I can\'t find which jar fi

11条回答
  •  天命终不由人
    2020-12-15 16:47

    As Location Client is deprecated the class is no more found in the package. We have to use the following instead

    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(LocationServices.API)
    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks(){
    
        @Override
        public void onConnected(Bundle arg0) {
            // TODO Auto-generated method stub
            LocationRequest request = new LocationRequest();
            int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
            if (enableHighAccuracy) {
              priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
            }
            request.setPriority(priority);
    
            LocationServices.FusedLocationApi.requestLocationUpdates(
                    locationClient, request, new LocationListener() {
    
                      @Override
                      public void onLocationChanged(Location location) {
    
                        locationClient.disconnect();
                      }
    
            });
        }
    
        @Override
        public void onConnectionSuspended(int arg0) {
            // TODO Auto-generated method stub
    
        }
        })
    .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
    
        @Override
        public void onConnectionFailed(ConnectionResult arg0) {
            // TODO Auto-generated method stub
    
        }
    })
    .build();
    

提交回复
热议问题