Aşağıda belirtilen adımları izleyin
1) Bir oluşturun LocationRequestdileğin göre
LocationRequest mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000)
.setFastestInterval(1 * 1000);
2) BirLocationSettingsRequest.Builder
LocationSettingsRequest.Builder settingsBuilder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
settingsBuilder.setAlwaysShow(true);
3) alın LocationSettingsResponse TaskAşağıdaki kodu kullanarak
Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(this)
.checkLocationSettings(settingsBuilder.build());
Not: LocationServices.SettingsApi kullanımdan kaldırılmıştır, bu nedenle SettingsClientYerine kullanın .
4) Bir ekleme OnCompleteListenerTask.When gelen sonucu elde etmek için Tasktamamlamalar, istemci gelen durum koduna bakarak konum ayarlarını kontrol edebilirsiniz LocationSettingsResponsenesne.
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
@Override
public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
try {
LocationSettingsResponse response =
task.getResult(ApiException.class);
} catch (ApiException ex) {
switch (ex.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
ResolvableApiException resolvableApiException =
(ResolvableApiException) ex;
resolvableApiException
.startResolutionForResult(MapsActivity.this,
LOCATION_SETTINGS_REQUEST);
} catch (IntentSender.SendIntentException e) {
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
break;
}
}
}
});
DURUM 1: LocationSettingsStatusCodes.RESOLUTION_REQUIRED Konum etkin değil, ancak kullanıcıdan iletişim kutusuyla konumu açmasını isteyerek (arayarak startResolutionForResult) konumu etkinleştirmesini isteyebiliriz .

DURUM 2: LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE Konum ayarları tatmin edici değil. Ancak, ayarları düzeltmenin bir yolu yok, bu nedenle iletişim kutusunu göstermeyeceğiz.
5) OnActivityResult kullanıcı eylemini konum ayarları iletişim kutusunda alabiliriz. RESULT_OK=> Kullanıcı Konumu açtı. RESULT_CANCELLED- Kullanıcı konum ayarlama isteğini reddetti.