Suppose you are already using google play services and already connected (example below):
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}
Now it’s just:
@Override
public void onConnected(Bundle connectionHint) {
myLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (myLocation != null) {
latText.setText(String.valueOf(myLocation.getLatitude()));
longText.setText(String.valueOf(myLocation.getLongitude()));
}
}
Even, in the documentation has the example of how to get your own location also: Android Developers
I’m using Play service:11.8.0. But when I write Locationservices it doesn’t recognize
– Juliano Silveira