Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. private void initMap() {
  2.         String API_KEY = BuildConfig.APIKey;
  3.         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  4.  
  5.         mapFragment.getMapAsync(new OnMapReadyCallback() {
  6.             @Override
  7.             public void onMapReady(GoogleMap googleMap) {
  8.                 Log.d("Map" , "map is ready");
  9.                 gMap = googleMap;
  10.  
  11.                 if (locationPermissionsGranted) {
  12.                     getDeviceLocation();
  13.                     if (!hasPermissions(MapActivity.this, PERMISSIONS)) {
  14.                         ActivityCompat.requestPermissions(MapActivity.this, PERMISSIONS, permissionAll);
  15.                     }else {
  16.                         gMap.setMyLocationEnabled(true);
  17.                     }
  18.  
  19.                 }
  20.             }
  21.         });
  22.     }
  23.     public static boolean hasPermissions(Context context, String... permissions) {
  24.         if (context != null && permissions != null) {
  25.             for (String permission : permissions) {
  26.                 if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
  27.                     return false;
  28.                 }
  29.             }
  30.         }
  31.         return true;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement