Last time I put the code on oncreate method which can successfully capture the device longitude and latitude but currently I run again and it show nothing please anyone can advice me on this question? original should be can found in last month but currently cannot found!
The code is like this.
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000 , 0, (LocationListener) this);
//get Location
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
la = String.valueOf(location.getLatitude());
searchla.setText("Latitude: "+ la);
lo = String.valueOf(location.getLongitude());
searchlo.setText("Longitude: "+lo);
so did i miss out something?