1. package com.androidexample.gpsbasics;
  2. import android.location.Location;
  3. import android.location.LocationListener;
  4. import android.location.LocationManager;
  5. import android.os.Bundle;
  6. import android.widget.Toast;
  7. import android.app.Activity;
  8. import android.content.Context;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11. public class GpsBasicsAndroidExample extends Activity implements LocationListener {
  12. private LocationManager locationManager;
  13. private Button btnShowLocation;
  14. private Location _location;
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_gps_basics_android_example);
  19. locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  20. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, this);
  21. btnShowLocation = (Button)findViewById(R.id.Konum_Goster);
  22. btnShowLocation.setOnClickListener(new OnClickListener() {
  23. @Override
  24. public void onClick(View v) {
  25. if(_location!=null)
  26. {
  27. String str = "Enlem: "+ _location.getLatitude()+" \nBoylam: "+_location.getLongitude();
  28. Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
  29. }
  30. }
  31. });
  32. }
  33. public void onLocationChanged(Location location) {
  34. _location = location;
  35. }
  36. public void onStatusChanged(String provider, int status, Bundle extras) {
  37. }
  38. public void onProviderEnabled(String provider) {
  39. }
  40. public void onProviderDisabled(String provider) {
  41. }
  42. }