I have a problem with the user's position on one of my tester phones. This always works well for me, so I don’t know what the difference is.
Here is the sequence:
1: reboots your phone. 2. Checks to make sure location services are turned on (for both GPS and network). 3. Launches my application.
The OS never provides the correct location. GetLastKnownLocation () always returns null for both GPS_PROVIDER and NETWORK_PROVIDER, and the LocationListener is never called after the LocatioUpdates request.
- Then it launches the Google Maps application (which seems to find it).
- Then, if it starts my application again and it sets the location correctly.
Here is the basic information about my code:
LocationManager locationManager = (LocationManager) this.getSystemService( Context.LOCATION_SERVICE );
LocationListener locationListener = new LocationListener()
{
public void onLocationChanged( Location location )
{
useLocation( location );
}
public void onStatusChanged( String provider, int status, Bundle extras )
{
}
public void onProviderEnabled( String provider )
{
}
public void onProviderDisabled( String provider )
{
}
};
String provider = locationManager.getBestProvider( new Criteria(), true );
if ( provider != null )
{
System.out.println( "Using provider: " + provider );
locationManager.requestLocationUpdates( provider, 120 * 1000, 10000, locationListener );
}
Location lastLocation = locationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER );
if ( lastLocation != null )
useLocation( lastLocation );
else
useLocation( locationManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER ) );
, , - "", . onLocationChanged . getLastKnowLocation().
- , , ?