URL and Link repository

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.
wargps = (EditText) findViewById(R.id.wargps);
locbtn = (Button) findViewById(R.id.locbtn);
locbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
FusedLocationProviderClient fusedLocationProviderClient =
Task task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener () {
public void onSuccess(Location location) {
if(location!=null) {
wargps.setText(location.getLatitude()+" "+location.getLongitude());
locbtn.setText("Got Location");