0

I'm trying to clone Uber, I want to access the driver current location, but when implementing LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient,locationRequest,this); Iam getting an error as follow:

Cannot resolve method 'requestLocationUpdates(com.google.android.gms.common.api.GoogleApiClient, android.location.LocationRequest, com.example.codingcafe.cab.DriversMapActivity)'

This is my class, I tried to add LocationListener to the implements, I changed the gms-location implementation in the build.gradle, nothing worked

package com.example.codingcafe.cab;


import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationRequest;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;

import com.example.codingcafe.cab.databinding.ActivityDriversMapBinding;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.location.LocationListener;

public class DriversMapActivity extends FragmentActivity implements OnMapReadyCallback,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        com.google.android.gms.location.LocationListener{

    private GoogleMap mMap;
    private ActivityDriversMapBinding binding;
    GoogleApiClient googleApiClient;
    Location LastLocation;
    LocationRequest locationRequest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityDriversMapBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney,17));
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            locationRequest = new LocationRequest.Builder( 1000)
                    .setMinUpdateIntervalMillis(500)
                    .setQuality(LocationRequest.QUALITY_HIGH_ACCURACY)
                    .setMaxUpdateDelayMillis(1000)
                    .build();

        }

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
        {
            return;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient,locationRequest,this);

        //it will handle the refreshment of the location
        //if we dont call it we will get location only once

    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }

    @Override
    public void onLocationChanged(Location location) {

    }
}  
  • Please [edit] the post and include the full compiler error. – Turing85 Jan 04 '23 at 17:24
  • just looking at the nature of the exception seems to indicate you are possibly __a__ using a deprecated feature not supported anymore in the API you're compiling on and targeting, __b__ using an identical named component, but from a different native android package or __c__ the component used by uber or what you're referencing has the same name, but is actually third party component provided by an external lib you have to implemment on your gradle build script. – mindoverflow Jan 04 '23 at 18:59
  • ah yes there we go: https://stackoverflow.com/questions/57410135/fusedlocationapi-is-deprecated – mindoverflow Jan 04 '23 at 19:05
  • [another one](https://stackoverflow.com/questions/46481789/android-locationservices-fusedlocationapi-deprecated). to be honest, android backward compatibility support is a __proper mess__. may i suggest searching ```site:github.com android location api``` on google for third party in-packaged solutions for an even experience. every new API messes up device hard access, perhaps due to fast rate of tech growth / security-efficiency-design issues – mindoverflow Jan 04 '23 at 19:14
  • unfortunately this doesn't help me – Mohamad Software Jan 04 '23 at 19:32
  • please paste stacktrace as well – Giovanni Contreras Jan 05 '23 at 01:58

0 Answers0