title: Getting the first GPS coordinate (before moving around) in Android
body: <p>I'm creating an app that requires GPS location (or some location).</p>
  
  <p>However after setting up the listener and and all, i never get that first GPS location, i mean the location when i open the program (and just sitting still).</p>
  
  <p>I can get the last known location, but since the GPS is turned of when the program isn't running (or so it seems) then i dont know if this is the correct Location</p>
  
  <p>When i open Google maps, it only takes a few seconds before it moves to the actual location, it it gives a message about "waiting for location", so i dont know what i'm doing wrong (or if this is normal).. This is my GPS code:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      LocationManager loc = null;
      LocationListener listener;
  
  
      loc = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE) ;
  
      Context context = getApplicationContext();
      Location last = loc.getLastKnownLocation(LocationManager.GPS_PROVIDER) ;
  
      Toast toast = Toast.makeText(context, "GPS:" + last  , Toast.LENGTH_LONG );
      toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);
      toast.show();
  
      listener = new LocationListener() {
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
              // TODO Auto-generated method stub
              Context context = getApplicationContext();
              Toast toast = Toast.makeText(context, "Status changed", Toast.LENGTH_LONG );
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);
              toast.show();
  
  
       }
  
          @Override
          public void onProviderEnabled(String provider) {
              // TODO Auto-generated method stub
              Context context = getApplicationContext();
              Toast toast = Toast.makeText(context, "GPS enabled", Toast.LENGTH_LONG );
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);
              toast.show();
          }
  
          @Override
          public void onProviderDisabled(String provider) {
              // TODO Auto-generated method stub
              Context context = getApplicationContext();
              Toast toast = Toast.makeText(context, "GPS disabled", Toast.LENGTH_LONG );
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);
              toast.show();
          }
  
          @Override
          public void onLocationChanged(Location location) {
              // TODO Auto-generated method stub
              if (location == null) return ; 
              Context context = getApplicationContext();
              Toast toast = Toast.makeText(context, "coords:" + location, Toast.LENGTH_LONG );
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);
              toast.show();
          }
  
      };
  
      Criteria criteria = new Criteria();
      criteria.setAccuracy(Criteria.ACCURACY_FINE);
      criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
      String bestProvider = loc.getBestProvider(criteria, true); 
  
      loc.requestLocationUpdates(bestProvider, 1000, 0, listener) ;
  </code></pre>
  
  <p>So my question is, is there some way of invoking something and getting the current GPS coordinates, or does the last known location contains the precise coordinates if the GPS is turned on (but not running - by which i mean blinking in the top)?
  And what about when i use the getbestprovider, then i dont know if the last one used was GPS or WIFI or something.</p>