title: Gps android - getting Latitude and Longitude
body: <p>Can you help me with that.. application started to crash when I added the geocoder to get the name of the city by using latitude and longitude..</p>
  
  <pre><code>    double latitude, longitude;
      private TextView lala;
  
      LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
      Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
      longitude = location.getLongitude();
      latitude = location.getLatitude();
      final LocationListener locationListener = new LocationListener() {
          public void onLocationChanged(Location location) {
              longitude = location.getLongitude();
              latitude = location.getLatitude();
          }
  
          public void onProviderDisabled(String arg0) {
              // TODO Auto-generated method stub
  
          }
  
          public void onProviderEnabled(String arg0) {
              // TODO Auto-generated method stub
  
          }
  
          public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
              // TODO Auto-generated method stub
  
          }
      };
  
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
      lala = (TextView) findViewById(R.id.textView1);
  
      Geocoder myLocation = new Geocoder(getApplicationContext(), Locale.getDefault());   
      List&lt;Address&gt; myList = null;
      try {
          myList = myLocation.getFromLocation(latitude, longitude, 1);
      } catch (IOException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  
  
      lala.setText((CharSequence) myList);
  </code></pre>