Android 4.3 on Moto G, Android 4.4.2 on Nexus 7 2012, Android 4.4.2 on Nexus 5. Android Studio 0.4.
I don't want to receive regular location updates, I just want an accurate location when the user presses a button.
I have followed this example: https://developer.android.com/training/location/retrieve-current.html
In manifest file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I check that Play Services are available using GooglePlayServicesUtil.isGooglePlayServicesAvailable
In main activity:
//in activity onCreate method
mLocationClient = new LocationClient(this, this, this);
@Override
protected void onStart() {
mLocationClient.connect();
super.onStart();
}
@Override
protected void onStop() {
mLocationClient.disconnect();
super.onStop();
}
//in button onclick method
mCurrentLocation = mLocationClient.getLastLocation();
I have no SIM card. If I enable Wifi then sometimes I get an accurate location. Other times mCurrentLocation is null.
If I disable Wifi then mCurrentLocation is always null.
I am testing outside in several locations always with a clear view of the sky. I waited three minutes in each location.
I never see the GPS icon appear on the Android notification bar at the top of the screen.
I have these location settings:
A GPS Test app manages to use GPS successfully indoors on the same device with Wi-Fi disabled so GPS is working:
Registering for location updates, as at https://developer.android.com/training/location/receive-location-updates.html, doesn't work either. Registered method never called.
What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…