title: GPS provider not showing current location at first time
body: <p>i am trying to get location from both network provider and gps.By using the returned latitude and longitude i am placing markers on map. When i tried with network provider app is working fine.But when i tried to get location from gps, for the <strong>first time it is returning null</strong>. After that it is giving me exact location result. How to get rid from this.?</p>
  
  <p>I think some minor changes i have to made, please suggest me in fixing this.</p>
  
  <p>this is how i am doing this.</p>
  
  <pre><code>    public class MapActivity extends Activity implements LocationListener {
  
  
              private GoogleMap gMap;
              private LocationManager locationManager;
              private String provider;
              boolean gps_enabled = false;
              boolean netwrk_enabled = false;
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_map);
                  gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                          .getMap();
  
      //Focussing india on starting map
                  gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
                          23.40276491, 77.51953125), 5));
  
                  locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this);
  
                  gps_enabled = locationManager
                          .isProviderEnabled(LocationManager.GPS_PROVIDER);
  
                  netwrk_enabled = locationManager
                          .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                  if (gps_enabled)
                      provider = LocationManager.GPS_PROVIDER;
                  else
                      provider = LocationManager.NETWORK_PROVIDER;
  
                  Criteria criteria = new Criteria();
                  provider = locationManager.getBestProvider(criteria, false);
  
                  Location location = locationManager.getLastKnownLocation(provider);
  
  
  
      CameraPosition cp = new CameraPosition(new LatLng(
                          location.getLatitude(), location.getLongitude()), 14, 40, 90);
                  gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp), 4000,
                          null);
                  gMap.addMarker(new MarkerOptions().position(
                          new LatLng(location.getLatitude(), location.getLongitude()))
                          .title("I am here"));
  
                  if (location != null) {
  
                      if (provider == LocationManager.GPS_PROVIDER)
                          Toast.makeText(getApplicationContext(), "taking from gps",
                                  Toast.LENGTH_SHORT).show();
  
                      else if (provider == LocationManager.NETWORK_PROVIDER)
                          Toast.makeText(getApplicationContext(), "taking from network",
                                  Toast.LENGTH_SHORT).show();
  
                      new HttpGetTask().execute();
                  }
  
              }
  
              @Override
              protected void onPause() {
                  // TODO Auto-generated method stub18d1:d002
                  super.onPause();
                  locationManager.removeUpdates(this);
              }
  
              @Override
              protected void onResume() {
                  // TODO Auto-generated method stub
                  super.onResume();
                  locationManager.requestLocationUpdates(provider, 400, 1, this);
              }
  
              @Override
              public boolean onCreateOptionsMenu(Menu menu) {
                  // Inflate the menu; this adds items to the action bar if it is present.
                  getMenuInflater().inflate(R.menu.map, menu);
                  return true;
              }
  
              @Override
              public void onLocationChanged(Location location) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onProviderDisabled(String provider) {
                  // TODO Auto-generated method stub
                  Toast.makeText(this, "Disabled provider " + provider,
                          Toast.LENGTH_SHORT).show();
  
              }
  
              @Override
              public void onProviderEnabled(String provider) {
                  // TODO Auto-generated method stub
  
                  Toast.makeText(this, "Enabled new provider " + provider,
                          Toast.LENGTH_SHORT).show();
  
              }
  
              @Override
              public void onStatusChanged(String provider, int status, Bundle extras) {
                  // TODO Auto-generated method stub
  
              }
  
              private class HttpGetTask extends AsyncTask&lt;Void, Void, String&gt; {
  
          //Passing latitude and longitude here to get lat longs from my remote server.
          // using json parsing i am placing multiple markers here.
  
  
              }
  
          }
  </code></pre>