title: Get String from Location Android
body: <p>I found a great function which gives me possibility to get Location quickly.
  After that i want to display its (longitude and latitude) but it doest work still i get 0.0 / 0.0. </p>
  
  <p>here's code </p>
  
  <p>What should i do if i want display this latitude and longitude mostly I'm interested in function getLastKnownLocation because i want display this data without using GPS or Internet</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener
  </code></pre>
  
  <p>{</p>
  
  <pre><code>private static final long MIN_TIME_BW_UPDATES = 0;
  private static final float MIN_DISTANCE_CHANGE_FOR_UPDATES = 0;
  public EditText lokalizacja;
  public Button pobierz;
  private static Context context;
  LocationManager locationManager;
  
  // flag for GPS status
  boolean isGPSEnabled = false;
  
  // flag for network status
  boolean isNetworkEnabled = false;
  
  // flag for GPS status
  boolean canGetLocation = false;
  
  Location location; // location
  double latitude ; // latitude
  double longitude; // longitude
  
  
  
  public static Context getContext()
  {
      return context;
  }
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      lokalizacja = (EditText) findViewById(R.id.editText1);
      pobierz = (Button) findViewById(R.id.button1);
  
  
      pobierz.setOnClickListener(this);
  
  }
  
  
  @Override
  public void onClick(View v)
  {   
  
      getLocation();  
  
  }
  
  
  public Location getLocation() {
      try {
          locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
  
          // 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
          } else {
              this.canGetLocation = true;
  
              if (isNetworkEnabled) {
                  locationManager.requestLocationUpdates(
                          LocationManager.NETWORK_PROVIDER,
                          MIN_TIME_BW_UPDATES,
                          MIN_DISTANCE_CHANGE_FOR_UPDATES, (LocationListener) this);
                  Log.d("Network", "Network Enabled");
                  if (locationManager != null) {
                      location = locationManager
                              .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                      if (location != null) {
                          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,
                              MIN_TIME_BW_UPDATES,
                              MIN_DISTANCE_CHANGE_FOR_UPDATES, (LocationListener) this);
                      Log.d("GPS", "GPS Enabled");
                      if (locationManager != null) {
                          location = locationManager
                                  .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                          if (location != null) {
                               latitude = location.getLatitude();
                              longitude = location.getLongitude();
  
                          }
                      }
                  }
              }
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      String napis = String.valueOf(latitude+ "\n" + longitude);
        lokalizacja.setText(napis);
      return location;
  
  }  
  </code></pre>
  
  <p>}</p>