I want to retrieve the longitude and latitude of a device and just edit a textview with the data I obtained.. Here is where I left because I dunno what to do:
public class Login_activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_activity);
final TextView locationText = (TextView) findViewById(R.id.textView);
final Button locationRetrieveButton = (Button) findViewById(R.id.button);
final Location locationConst = new Location(LocationManager.GPS_PROVIDER);
final double locationX = locationConst.getLatitude();
final double locationY = locationConst.getLongitude();
final View.OnTouchListener retrieveButtonClicked = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
locationText.setText("FirstX:"+locationX+"\nFirstY="+locationY+"\nSecondX=\nSecondY=\n"+locationConst.getProvider());
return false;
}
};
locationRetrieveButton.setOnTouchListener(retrieveButtonClicked);
}
When I click the "locationRetrieveButton" the locationX and locationY variables just return 0.0 and 0.0, the GPS_PROVIDER is "gps". I've included all needed permissions in the android manifest (Coarse location and fine location and internet permissions as well). What am I missing ?