- package com.androidexample.gpsbasics;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.os.Bundle;
- import android.widget.Toast;
- import android.app.Activity;
- import android.content.Context;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- public class GpsBasicsAndroidExample extends Activity implements LocationListener {
- private LocationManager locationManager;
- private Button btnShowLocation;
- private Location _location;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_gps_basics_android_example);
- locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, this);
- btnShowLocation = (Button)findViewById(R.id.Konum_Goster);
- btnShowLocation.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if(_location!=null)
- {
- String str = "Enlem: "+ _location.getLatitude()+" \nBoylam: "+_location.getLongitude();
- Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
- }
- }
- });
- }
- public void onLocationChanged(Location location) {
- _location = location;
- }
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
- public void onProviderEnabled(String provider) {
- }
- public void onProviderDisabled(String provider) {
- }
- }