0

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?

learner
  • 11,490
  • 26
  • 97
  • 169
  • 1
    All ways of getting a location from the map reference have been deprecated. The current advise from Google is to use FusedLocationApi for all location based functionality in your app. For implementation see here: http://stackoverflow.com/a/30255219 – Daniel Nugent Nov 29 '15 at 19:00
  • I see. Thank you. +1 – learner Nov 29 '15 at 20:36

0 Answers0