Skip to content

Instantly share code, notes, and snippets.

@azec-pdx
Created December 18, 2014 18:11
Show Gist options
  • Select an option

  • Save azec-pdx/ecef5e192ddb08cbd138 to your computer and use it in GitHub Desktop.

Select an option

Save azec-pdx/ecef5e192ddb08cbd138 to your computer and use it in GitHub Desktop.
Glavni Activity za GPS primjer
package ba.edu.eksa.gpstest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class GPSActivity extends Activity {
Button btnShowLocation;
// GPSTracker class
GPSTracker gps;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// create class object
gps = new GPSTracker(GPSActivity.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();
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment