I am implementing google maps api as a fragment in my project but I am getting error while adding setmylocationenabled(true). Please help me with this. The error is:- "Call requires permission which may be rejected by the user.Code should explicitly check to see if permission is available(with 'checkPermission') or explicitly handle a potential 'Security Exception'
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.testgmaps.R;
public class GmapFragment extends Fragment implements OnMapReadyCallback {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_gmaps, container,false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap mMap) {
mMap.setMyLocationEnabled(true);
LatLng marker = new LatLng(-33.867, 151.206);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(marker, 13));
mMap.addMarker(new MarkerOptions().title("Google Maps Test Marker").position(marker));
}
}