Created
December 18, 2014 18:11
-
-
Save azec-pdx/ecef5e192ddb08cbd138 to your computer and use it in GitHub Desktop.
Glavni Activity za GPS primjer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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