Click here to Skip to main content
15,843,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to get the current location using android studio but always the variable currentLocation has null value

and the android studio draw red line under
Location currentLocation= LocationServices.FusedLocationApi.getLastLocation(mLocationclient);

and asked to check the permission I tried two ways with checking permission and without but the same result return null value

please who can help me? this is the code I have used

 private GoogleApiClient mLocationclient;
mLocationclient=new GoogleApiClient.Builder(this)

            Location currentLocation= LocationServices.FusedLocationApi.getLastLocation(mLocationclient);
                Toast.makeText(this,"could not connect",Toast.LENGTH_SHORT).show();
            else {
                LatLng ll=new LatLng(
                CameraUpdate update=CameraUpdateFactory.newLatLngZoom(ll,50);

What I have tried:

I try (( mMap.setMyLocationEnabled(true); )) and it works fine
but programmatically does not work and always return null value to the variable currentLocation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900