I have very interesting problem, My Location manager sometimes working, sometimes returning null data.
I check all permission , gradle files options and runtime check about location is enabled. My phone not have airplane mode and I do not off location.
Whatever I check all data, There is no trouble for the get the location data.
Main Code
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        cs = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("verigeldi");
         mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
         location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return; // check permission
        }
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,1000, mLocationListener);
    }
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
try { // THIS AREA VERY IMPORTANT !!!!
    longitude = location.getLongitude(); // GET NULL POINTER EXCEPTION SOMETIMES WORKING
    latitude = location.getLatitude(); // GET NULL POINTER EXCEPTION SOME TIMES WORKING
    LatLng latLng = new LatLng(latitude, longitude);
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 13);
    mMap.animateCamera(cameraUpdate);
            }
catch (Exception e) {
    LatLng latLng = new LatLng(39.052540, 35.410083); 
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 5);
    mMap.animateCamera(cameraUpdate);
    }
        checkLocationIsEnabled();
        googleMap.getUiSettings().setMyLocationButtonEnabled(true);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        googleMap.setMyLocationEnabled(true);
    }
       public final LocationListener mLocationListener = new LocationListener() {
           @Override
           public void onLocationChanged(Location location) {
               LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
               CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 13);
               mMap.animateCamera(cameraUpdate);
               mLocationManager.removeUpdates(this);
           }
           @Override
           public void onStatusChanged(String provider, int status, Bundle extras) {
           }
           @Override
           public void onProviderEnabled(String provider) {
           }
           @Override
           public void onProviderDisabled(String provider) {
           }
       };
