I am trying to get the longitude and latitude but set it on a text view but idk why its not working i tried everything but i am not getting any results i am getting the permisiion dialog box but unable to show it
this is my main activity
package com.example.morror;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.tasks.OnSuccessListener;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
public class SplashActivity extends AppCompatActivity {
private final static int REQUEST_CODE = 100;
private TextView introTextView;
FusedLocationProviderClient hello;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
hello= new FusedLocationProviderClient(SplashActivity.this);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(SplashActivity.this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_CODE);
}
introTextView = findViewById(R.id.intro);
getlastLocation();
}
private void letsgo() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent home=new Intent(SplashActivity.this,MainActivity.class);
startActivity(home);
}
}, 4000);
}
private void getlastLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
hello.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
introTextView.setText("Latitude: " + latitude + "\nLongitude: " + longitude);
}
}
});
}
}
}
I was trying to get the longitude and latitude using google play services