title: Get current latitude and longitude in the string
body: <p>I am trying to get <code>latitude</code> and <code>longitude</code> but sometime <code>network is available</code> but I am not getting value of <code>latitude</code> and <code>longitude</code>. I am using <strong>MyLocationListener</strong> class and put condition all but some time <code>value</code> is not getting.</p>
  
  <pre><code>protected void showCurrentLocation() 
  {
      Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
      if (location != null) 
      {
          counter++;          
          latitude=location.getLatitude();
          longitude=location.getLongitude();
          altitude=location.getAltitude();
      }
   }   
  
  private class MyLocationListener implements LocationListener
  {
      @Override
      public void onLocationChanged(Location location)
      {
           counter++;
           latitude=location.getLatitude();
           longitude=location.getLongitude();
           altitude=location.getAltitude();
      }
  
      @Override
      public void onStatusChanged(String s, int i, Bundle b) 
      {
      }
      @Override
      public void onProviderDisabled(String s) 
      {   
      }
      @Override
      public void onProviderEnabled(String s) 
      {
      }
  }
  </code></pre>