Merhaba uygulamam açıldığında harita geliyor ben haritada telefonun konumu görülsün istiyorum fakat yapmadım.Ben buttona tıklanınca konumu alabilen bir kod yazdım ama onu uygulama ilk açıldığında çalıştıramıyorum.Ne yapmalıyım onMapReady methodunun içine el ile enlem boylam girildiğinde oluyor fakat
Merhaba uygulamam açıldığında harita geliyor ben haritada telefonun konumu görülsün istiyorum fakat yapmadım.
Ben buttona tıklanınca konumu alabilen bir kod yazdım ama onu uygulama ilk açıldığında çalıştıramıyorum.
Ne yapmalıyım onMapReady methodunun içine el ile enlem boylam girildiğinde oluyor fakat telefonun konumunu onMapReady içine alamıyorum.
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;
private int izinKontrol;
private Button btn;
private TextView textone,texttwo;
private String konumSaglayici = "gps";
private LocationManager locationManager;
private GoogleMap mMap;
private double d, e;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ff();
}
});
Log.e("ccc", "ccc");
textone = findViewById(R.id.r);
texttwo = findViewById(R.id.t);
// 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);
}
public void ff(){
izinKontrol = ContextCompat.checkSelfPermission(MapsActivity.this, Manifest.permission.ACCESS_FINE_LOCATION);
if(izinKontrol != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MapsActivity.this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},100);
}else{
Location konum = locationManager.getLastKnownLocation(konumSaglayici);
if(konum!=null){
onLocationChanged(konum);
}else{
textone.setText("Konum Aktif DEĞİL
*