How to get Current GPS location(latitude-longitude) using Google API in Android App?

Viewed 1615

I want to get GPS location using Google API.

My code:

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

@Override
public void onConnected(Bundle bundle) {  
    mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    double lat = mLocation.getLatitude();
    double lon = mLocation.getLongitude();
}

I am not getting anything in the lat and lon variables.

How do I solve it?

1 Answers
Related