Reputation: 11
hello guys, please help me. I don't know what to do
I have also done the suggestion that has been given android studio
Upvotes: 0
Views: 118
Reputation: 2577
These both errors are different.
mapFragment.getMapAsync(this)
setMyLocationEnable
needs to check for run time permission of ACCESS_COARSE_LOCATION
and ACCESS_FINE_LOCATION
.for issue 1 try this:
mapFragment.getMapAsync(new OnMapReadyCallback(){
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
}
});
For issue 2 use this
if (googleMap != null) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
googleMap.setMyLocationEnabled(true);
}
Upvotes: 0
Reputation: 1564
getMap() is deprecated. Use getMapAsync() like below.
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Upvotes: 1