0

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" />
......
Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
  • 1
    ... and if you open Google Maps it will show your current position? I assume also that you have set the proper permissions, right? – gunar Jun 14 '13 at 13:27
  • Yes, please make sure you have the location permissions in your manifest, and that the device doesn't have location disabled. – Matt Jun 14 '13 at 14:20
  • thanks for rplying but i do complete my home work and only problem in grand i dnt know y ??? – duggu Jun 14 '13 at 14:31

1 Answers1

1

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 ;
Community
  • 1
  • 1
Siddharth
  • 9,349
  • 16
  • 86
  • 148
  • I have implements LocationListener and Override onStatusChanged, onProviderEnabled, onProviderDisabled, onLocationChanged. Bad luck not getting location. Please help me – Murali Ganesan Nov 11 '14 at 07:25
  • I have pasted code http://codepad.org/bXtyUqpr Please check and let me know. What is wrong in that code? please help me – Murali Ganesan Nov 12 '14 at 04:15
  • please please use stackoverflow. this is not the way to ask for help. you already have 800 reputation, use that. – Siddharth Nov 12 '14 at 04:23
  • 1
    Are you serious ? http://stackoverflow.com/questions/22293679/android-l istview-item-collapse-while-scrolling is your question dude. – Siddharth Nov 12 '14 at 05:06
  • Then take the time to read other questions to answer your question. Noone has the time for this kinda chat help. – Siddharth Nov 12 '14 at 06:23
  • ok lemme try another answers. main problem is some of device not getting location. Please feel free and help me how to resolve this – Murali Ganesan Nov 12 '14 at 06:43