I am developing an app that needs current lat and long of the user at start up. Currently i am getting lat and long of an user like this:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
public void onConnected(Bundle connectionHint) {
LocationRequest mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setInterval(1000); // Update location every second
mLocationRequest.setNumUpdates(1);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
Different listeners that are needed for location requests are implemented in Activity.
Sometimes the request takes 1-2 seconds then other times 15 seconds and sometimes even more. My question is: am i doing anything wrong that i am not seeing?
Using GetLastKnownLocation() is not an option because i need current location.
Any tips would be greatly appreciated.