Widespread Augmented Reality

Widespread Augmented Reality
Click on the image to get the Android Augmented Reality Heads up Display

Saturday, April 20, 2019

Android FusedLocationProviderClient

In hopes of obtaining GPS location faster, I implemented the FusedLocationProviderClient and removed the old LocationManager.GPS_PROVIDER. Below is a snippet of the new simpler approach that I used in the latest update of Widespread Augmented Reality.
setContentView(R.layout.main);
wargps = (EditText) findViewById(R.id.wargps);
locbtn = (Button) findViewById(R.id.locbtn);
locbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FusedLocationProviderClient fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(getApplicationContext());
Task task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener () {
@Override
public void onSuccess(Location location) {
if(location!=null) {
wargps.setText(location.getLatitude()+" "+location.getLongitude());
locbtn.setText("Got Location");
}}});
}
});

No comments:

Post a Comment