Skip to content Skip to sidebar Skip to footer

Longitude And Latiude Null In Android

I have a GPSTracker file but in the android M iam geting a zero on the locations... i ask for your help to solve this problem...see the code below Fragment with the location and a

Solution 1:

Since your LocationListener tries to get location using only Network not GPS, with this code snippet: locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) probably you are getting latitude and longitude values but with a delay. I had the same problem then I begin to use new/latest Location service API and use: GoogleApiClient. First you need to implement

GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        LocationListener

from you activity that want to fetch the location data.

Define

private GoogleApiClient mGoogleApiClient;

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

If you haven't add

<uses-permission `android:name="android.permission.ACCESS_FINE_LOCATION"/>` 

to the manifest file, add that.

For further documentation : https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient

Post a Comment for "Longitude And Latiude Null In Android"