Subharanjan Nayak
Subharanjan Nayak

Reputation: 1

reference to onLocationChanged is ambiguous

I am trying to make a speedometer using implement LocationListener. How ever when make a call to onLocationChanged it is saying the reference to onLocationChanged is ambiguous

enter image description here

my codes :

//speedometer and llocation servie
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    Toast.makeText(this, "First enable LOCATION ACCESS in settings.", Toast.LENGTH_LONG).show();
    return;
}
LocationManager lm =(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,this);
this.onLocationChanged(null);

After trying for some time I realised it is because this was of doing it is probably deprecated

So I tried tweeking compile sdk from 32 to 29 which seemed to remove that error but added a lot of library related compile errors... somebody please Help !

Thanks in advance

If you have any alternative way of making a speedometer do tell

Upvotes: 0

Views: 65

Answers (1)

Bastien Jansen
Bastien Jansen

Reputation: 8846

The error indicates that there are two signatures for that method:

onLocationChanged(List<Location> locations)
onLocationChanged(Location location)

When using null, the compiler cannot determine which one of the two methods you are targeting. You need to cast null either to a Location or a List:

this.onLocationChanged((Location) null);
this.onLocationChanged((List<Location>) null);

Upvotes: 0

Related Questions