title: Not able to get location using GPS
body: <p>I am developing one app. In which, I need to get the current location of the user. I am getting current location using Network but when I start the GPS its not showing me current location. What coubld be the problem? </p>
  
  <pre><code>public Location getLocation() {
      try {
          locationManager = (LocationManager) mContext
                  .getSystemService(LOCATION_SERVICE);
  
          Criteria criteria = new Criteria();
          criteria.setAccuracy(Criteria.ACCURACY_FINE);
          criteria.setAltitudeRequired(false);
          criteria.setBearingRequired(false);
          criteria.setCostAllowed(true);
          criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
  
          String bestProvider = locationManager.getBestProvider(criteria, true);
  
          System.out.println("Best Provider:"+bestProvider);
  
          // getting GPS status
          isGPSEnabled = locationManager
                  .isProviderEnabled(LocationManager.GPS_PROVIDER);
  
          // getting network status
          isNetworkEnabled = locationManager
                  .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  
          if (!isGPSEnabled &amp;&amp; !isNetworkEnabled) {
              // no network provider is enabled
              Toast.makeText(mContext, "GPS and Network not enabled!", Toast.LENGTH_SHORT).show();
          } else {
              this.canGetLocation = true;
              if (isNetworkEnabled) {
                  locationManager.requestLocationUpdates(
                          //LocationManager.NETWORK_PROVIDER,
                          bestProvider,
                          MIN_TIME_BW_UPDATES,
                          MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                  Log.d("Network", "Network");
                  if (locationManager != null) {
                      location = locationManager
                              //.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                              .getLastKnownLocation(bestProvider);
                      if (location != null) {
                          startLatitude = location.getLatitude();
                          startLongitude = location.getLongitude();
  
                          latitude = location.getLatitude();
                          longitude = location.getLongitude();
                      }
                  }
              }
              // if GPS Enabled get lat/long using GPS Services
              if (isGPSEnabled) {
                  if (location == null) {
                      locationManager.requestLocationUpdates(
                              //LocationManager.GPS_PROVIDER,
                              bestProvider,
                              MIN_TIME_BW_UPDATES,
                              MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                      Log.d("GPS Enabled", "GPS Enabled");
                      if (locationManager != null) {
                          location = locationManager
                                  //.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                                  .getLastKnownLocation(bestProvider);
                          if (location != null) {
                              latitude = location.getLatitude();
                              longitude = location.getLongitude();
                          }
                      }
                  }
              }
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return location;
  }
  </code></pre>
  
  <p>I have added permissions:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>