私はランタイムのアクセス許可について学び始めています。私は地図を持っており、私は許可をしました。ユーザーが細かい位置を許可すると、マップは現在の位置にズームし、許可しないと地図はその場所にとどまります。私が場所に滞在する代わりにしたいことは、ユーザーが自分の場所へのアクセスを許可していない場合、マップは自分のカスタム位置にズームする必要があります(グリニッジ)。ユーザーがAndroidのマップのファインロケーションの許可を許可しない場合のデフォルトの場所の追加
マイマップフラグメント:
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_REQUEST_CODE);
}
return;
}
mMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
// if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION)
// == PackageManager.PERMISSION_GRANTED) {
// mMap.setMyLocationEnabled(true);
// } else {
// // Show rationale and request permission.
// }
//Disable Map Toolbar:
mMap.getUiSettings().setMapToolbarEnabled(false);
// Get the name of the best provider and current location
String provider = null;
if (locationManager != null) {
provider = locationManager.getBestProvider(criteria, true);
}
// Get current location
Location myLocation = null;
if (locationManager != null) {
myLocation = locationManager.getLastKnownLocation(provider);
}
// Set default latitude and longitude to Greenwich
double latitude = 51.4825766;
double longitude = -0.0076589;
// Get latitude and longitude of the current location and a LatLng object
if (myLocation != null) {
latitude = myLocation.getLatitude();
longitude = myLocation.getLongitude();
}
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude, longitude)).zoom(14).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
}
このコードはどこに置く必要がありますか? – Kemo
最後のIF条件の後 –
私のコードを更新しました。これは既に自分のコードにあります。私が望むのは、ユーザーが許可を許可しないクリックをしたときに、カスタムの場所に移動する必要があるということです。 – Kemo