@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Getting locationManager object
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//creating an empty criteria object
Criteria Criteria = new Criteria();
//Getting the name of provider that meet the criteria
provider = locationManager.getBestProvider(Criteria, false);
if(provider!=null && !provider.equals("")){
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider ,800000,1, this );
if(location!= null)
onLocationChanged(location);
else
Toast.makeText(getBaseContext(),
"Location can't be found" ,Toast.LENGTH_LONG)
.show();
}
else
{
Toast.makeText(getBaseContext(), " No provider found" , Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//Getting reference to tv_Longitude
TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude);
tvLongitude.setText("Longitude:" + location.getLongitude());
// Getting reference to tv_Latitude
TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude);
tvLatitude.setText("Latitude:" + location.getLatitude());
}
Log.d("Latitude","disable");