Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package ba.edu.eksa.gpstest;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.Toast;
  8.  
  9. public class GPSActivity extends Activity {
  10.  
  11. Button btnShowLocation;
  12.  
  13. // GPSTracker class
  14. GPSTracker gps;
  15.  
  16. @Override
  17. public void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_gps);
  20.  
  21. btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
  22.  
  23. // show location button click event
  24. btnShowLocation.setOnClickListener(new View.OnClickListener() {
  25.  
  26. @Override
  27. public void onClick(View arg0) {
  28. // create class object
  29. gps = new GPSTracker(GPSActivity.this);
  30.  
  31. // check if GPS enabled
  32. if(gps.canGetLocation()){
  33.  
  34. double latitude = gps.getLatitude();
  35. double longitude = gps.getLongitude();
  36.  
  37. // \n is for new line
  38. Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
  39. }else{
  40. // can't get location
  41. // GPS or Network is not enabled
  42. // Ask user to enable GPS/network in settings
  43. gps.showSettingsAlert();
  44. }
  45.  
  46. }
  47. });
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement