locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
t= (TextView)findViewById(R.id.textView);
s.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String locationProvider = LocationManager.NETWORK_PROVIDER;
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
double lat = lastKnownLocation.getLatitude();
double lon = lastKnownLocation.getLongitude();
t.setText(""+lat+""+lon);
}
});
This is my code and I'm trying to get approximate location of user. But i don't know why i'm getting null object reference exception. Is this the right way of doing? can anyone help me with getting user location with network? Should I add request location updates method to get last known location?