duggu
duggu

Reputation: 38439

getting null on current location on Samsung Galaxy Grand android?

I'm try to run my app on Samsung Galaxy Grand but its not showing my current location.

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Creating a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Getting the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    System.out.println("provider => " + provider);

    // Getting Current Location
    Location location = locationManager.getLastKnownLocation(provider);
    System.out.println("location  " + location);

but always this line return null locationManager.getLastKnownLocation(provider); but this app works fine in other phones like sony and lg.

i have try so many link but still same problem.

getLastKnownLocation() always returning null, all providers are DummyLocationProvider

Android LocationManager.getLastKnownLocation() returns null

Network provider and GPS provider returning null values

permission

<permission
    android:name="xx.xxx.xxx.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="xicom.biz.perdiem.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />


<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application android:label="@string/app_name" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyccccccccbvxcbpmFLAZwalBGM" />
......

Upvotes: 0

Views: 1444

Answers (1)

Siddharth
Siddharth

Reputation: 9584

Check this for the answer, for short

To programmatically kick start your app for "current location" run the following code before you call getLastKnownLocation

YOUR_APPLICATION_CONTEXT.getLocationManager().requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
    @Override
    public void onProviderEnabled(String provider) {
    }
    @Override
    public void onProviderDisabled(String provider) {
    }
    @Override
    public void onLocationChanged(final Location location) {
    }
});

Some recommendations for fixing GPSTracker issues may be, to set it as 1 min 1 meter

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1;
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 ;

Upvotes: 1

Related Questions