0

I'm a newbie to android.Now I'm building an application which contains a bottom navigation..in which one of it's fragment contains a map which shows the current location.But when I implemented setMyLocationEnabled(true); on the permission check it shows some error and here's my java code the map do not displays any current location or location button.Please help me. here's my xml code here's my manifest file

  • did you enable location permisssion in you manifest file ? or as runtime permission.. Please include your manifest. [https://developer.android.com/training/location/change-location-settings] possible duplicate of [https://stackoverflow.com/questions/17591147/how-to-get-current-location-in-android] – noone May 30 '18 at 07:42

1 Answers1

0

You are getting an error because you are passing this in the context parameter when you are checking your permissions. I'm assuming that you are extending Fragment and not FragementActivity in your class. You will need to pass getApplicationContext() to your Fragment's constructor and use that as your context or extend FragmentActivity to get rid of the error. You could also suppress the warning if you know that you already have permissions as shown below.

@SuppressLint("MissingPermission")
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setMyLocationEnabled(true);
}

I would only recommend doing this for testing purposes or if you are checking that you have permissions before launching your Map Fragment/Activity.

J. Jefferson
  • 980
  • 8
  • 12