0

I was wondering as to which method is best for getting the absolute most accurate current coordinates using Google Play Services. Would it be to use getLastLocation(), like so:

public class MainActivity extends FragmentActivity implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener {
    ...
    // Global variable to hold the current location
    Location mCurrentLocation;
    ...
    mCurrentLocation = mLocationClient.getLastLocation();
    ...
}

or to use an update callback, like so:

public class MainActivity extends FragmentActivity implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener,
        LocationListener {
    ...
    // Define the callback method that receives location updates
    @Override
    public void onLocationChanged(Location location) {
        // Report to the UI that the location was updated
        String msg = "Updated Location: " +
                Double.toString(location.getLatitude()) + "," +
                Double.toString(location.getLongitude());
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
    ...
}

Any thoughts?

John Roberts
  • 5,885
  • 21
  • 70
  • 124
  • I have created class that gives a callback as soon as GPS has gotten a first fix: http://stackoverflow.com/questions/19365035/location-servise-gps-force-closed/19366773#19366773 please upvote if it helps you – cYrixmorten Dec 13 '13 at 21:02
  • The time it takes for a coordinate to be collected is a big priority for me, so I'm not sure to how much use I can put this. – John Roberts Dec 13 '13 at 21:11
  • Alright, but nothing prevents you from using the fused location as you already do for starters and then swap to GPS as soon as the first fix has been made :) – cYrixmorten Dec 13 '13 at 21:28

1 Answers1

1

getLastLocation() is not guaranteed to be your current location its not even guarenteed to return you a location at all, if you are interested in your most accurate current location then requesting location updates is your best bet

tyczj
  • 71,600
  • 54
  • 194
  • 296