content: package com.example.gpsapplication;
  
  import android.Manifest;
  import android.app.Activity;
  import android.content.pm.PackageManager;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  
  import androidx.core.app.ActivityCompat;
  
  
  public class MainActivity extends Activity {
  
      Button btnShowLocation;
      private static final int REQUEST_CODE_PERMISSION = 2;
      String mPermission = Manifest.permission.ACCESS_FINE_LOCATION;
  
      // GPSTracker class
      GPSTracker gps;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          try {
              if (ActivityCompat.checkSelfPermission(this, mPermission)
                      != PackageManager.PERMISSION_GRANTED) {
  
                  ActivityCompat.requestPermissions(this, new String[]{mPermission},
                          REQUEST_CODE_PERMISSION);
  
  
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          btnShowLocation = (Button) findViewById(R.id.button);
  
          // show location button click event
          btnShowLocation.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // create class object
                  gps = new GPSTracker(MainActivity.this);
  
                  // check if GPS enabled
                  if(gps.canGetLocation()){
  
                      double latitude = gps.getLatitude();
                      double longitude = gps.getLongitude();
  
                      // \n is for new line
                      Toast.makeText(getApplicationContext(), "Your Location is - \nLat: "
                              + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
                  }else{
                      // can't get location
                      // GPS or Network is not enabled
                      // Ask user to enable GPS/network in settings
                      gps.showSettingsAlert();
                  }
  
              }
          });
      }
  }