Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a bit of research this is what I came up with:</p> <pre><code>public class UseGps extends Activity { Button gps_button; TextView gps_text; LocationManager mlocManager; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gps_button = (Button) findViewById(R.id.GPSButton); gps_text = (TextView) findViewById(R.id.GPSText); gps_button.setOnClickListener(new OnClickListener() { public void onClick(View viewParam) { gps_text.append("\n\nSearching for current location. Please hold..."); gps_button.setEnabled(false); mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener); } }); } /* Class My Location Listener */ public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { double lon = loc.getLatitude(); double lat = loc.getLongitude(); gps_text.append("\nLongitude: "+lon+" - Latitude: "+lat); UseGps.this.mlocManager.removeUpdates(this); gps_button.setEnabled(true); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } } </code></pre> <p>This sets up an activity with a button and textview. Set a listener on the button which starts the location manager.</p> <p>I have set up a class, <code>MyLocationListener</code>, which implements <code>LocationListener</code>, and then I override the <code>onLocationChanged()</code> method, basically telling it that the first location it gets it appends to the textview and then it removes the location manager.</p> <p>Thanks to those who helped and I hope this is of use to someone else.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload