I have a Map Activity (the android studio default) which looks like
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback{...}
I need to get the user's current location. Do I still have to use
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
}
}
which would mean keeping an instance of mGoogleApiClient
or can I use the mMap
field to generate the current location?
Now I understand if the user clicks on the myLocation button then I can get the location with mMap.getMyLocation
; but I am interested in the non-trivial case where the user has not clicked the button. How do I get the current location in such case?