title: getLastKnowLocation return null
body: <p>I was making an application, which has a MapView, in which I want to show a marker in the position obtained from the gps of the device when I press a button. The problem I have is that the first time I enter the mapview activity, the getLastKnowLocation returns null so it doesn't put the marker on the map, however if I go back to the MainActivity and then to the activity of the mapview ,I get a position and the marker is put on the map.</p>
  
  <p>I do not know if I should use another method instead of getLastKnowLocation.</p>
  
  <p>I put the code in which I have not yet implemented the GPS permission and the active GPS verification.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_incidencia_mapa);
  
      bt_getgps=(Button)findViewById(R.id.bt_getgps);
      bt_getgps.setOnClickListener(this);
  
      mapView = (MapView) findViewById(R.id.map_incidencia);
  
  
      if (mapView != null) {
          mapView.onCreate(null);
          mapView.onResume();
          mapView.getMapAsync(this);
      }
  
  
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
          //SOLICITUD DE PERMISOS
          return;
      }
  
  
      locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this);
  
      Location location = locationManager.getLastKnownLocation(locationManager.GPS_PROVIDER);
  
     if (location == null) {
          location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
      }
  
  
      if(location != null){
          lat=location.getLatitude();
          longi= location.getLongitude();
  
      }
  
  
  }
  </code></pre>
  
  <p>Onclick:</p>
  
  <pre><code>    public void onClick(View view) {
  
      if (lat != 0 &amp;&amp; longi != 0) {
  
          place = new LatLng(lat, longi);
  
  
          marcador = new MarkerOptions();
          marcador.position(place);
          marcador.title("Zona del incidencia");
          marcador.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_incidencia_mapa));
          marcador.draggable(true);
  
  
          gMap.setMinZoomPreference(5);
          gMap.addMarker(marcador);
  
          gMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place, 17));
  
          geocoder = new Geocoder(this, Locale.getDefault());
  
  
          try {
              direciones = geocoder.getFromLocation(lat, longi, 1);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          calle = direciones.get(0).getAddressLine(0);
  
  
          Toast.makeText(this, direciones.get(0).getAddressLine(0), Toast.LENGTH_LONG).show();
          bt_getgps.setText(direciones.get(0).getAddressLine(0));
  
  
  
      } else {
          Toast.makeText(this, "No hay longitud ni latitud", Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  </code></pre>