title: Display GPS location on screen - Android
body: <p>I'm following the guide here: <a href="http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/" rel="nofollow">http://www.firstdroid.com/2010/04/29/android-development-using-gps-to-get-current-location-2/</a></p>
  
  <p>I'm trying to make an android app that simply gets the devices GPS coordinates and display them on the screen. My code works fine in the emulator when I telnet to it and type "geo fix 30.0 30.0", but when I use it on my phone, it never gets the coordinates. My GPS is working fine, as I opened up Maps and it had my exact location. So something must be wrong with the following code:</p>
  
  <pre><code>import java.io.IOException;
  
  import android.app.Activity;
  import android.content.Context;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class BusAppActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          /* Use the LocationManager class to obtain GPS locations */
          LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
          LocationListener locListener = new MyLocationListener();
          locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locListener);
      }
  
     /* To test in the emulator, use the telnet commands:
      * telnet localhost 5554
      * geo fix 30.0 30.0 */
  
      /* Class My Location Listener */
  
      public class MyLocationListener implements LocationListener
      {
          TextView tv = (TextView) findViewById(R.id.textview);
  
          @Override
          public void onLocationChanged(Location loc){
              Log.d("tag", "Finding Latitude");
              double lat = loc.getLatitude();
              Log.d("tag", "Lat: "+String.valueOf(lat));
              Log.d("tag", "Finding Longitude");
              double lon = loc.getLongitude();
              Log.d("tag", "Lon: "+String.valueOf(lon));
              String Text = "My current location is: " +
              "\nLatitude = " + lat +
              "\nLongitude = " + lon;
  
              // Display location
              tv.setText(Text);
          }
  
          @Override
          public void onProviderDisabled(String provider){
              Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
          }
  
          @Override
          public void onProviderEnabled(String provider){
              Toast.makeText(getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras){
  
          }
      }
  }
  </code></pre>
  
  <p>Here is my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="gsingh.busapp"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:label="@string/app_name"
              android:name=".BusAppActivity" &gt;
              &lt;intent-filter &gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Maybe if it's not too much trouble, someone could build this project and try it on their phone? All that needs be to added is labelling the only textview to "textview".</p>