Answer the question
In order to leave comments, you need to log in
Get permission before downloading Google Maps Android map?
Hello, you need to get permission before downloading Google Maps Android map. Now it turns out that after agreeing to determine my location, the MyLocation button does not appear, but after restarting the application, the button is already in place. Logically, it is clear that you need to build permission before loading the map. However, all the physical moves of a part of the code to all possible places did not give a result.
The code itself:
protected void onCreate(Bundle savedInstanceState) {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_LOCATION_REQUEST_CODE
);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
}
if (MY_LOCATION_REQUEST_CODE == 1) {
} else {
}
mMap.getUiSettings().setMyLocationButtonEnabled(true);
Answer the question
In order to leave comments, you need to log in
RTFM
Permissions are checked in onCreate(), if not, request using requestPermissions(), then check the result of the request in onRequestPermissionsResult().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question