I am in a trouble about using LocationManager in Android. The Locations from all LocationProvider's getLastKnownLocation are not enough in accuracy. In my phone, Galaxy S3, 'network' and 'passive' give me the locations when I use the getLastKnownLocation method of the LocationProvider. 'gps' is disabled in my phone. The locations are..
network --> latitude : XX.5511981, longitude : XXX.1284714 passive --> latitude : XX.5511981, longitude : XXX.1284714
Both give me same location information. But the location is very wrong. It is about 50Km wrong location.
In that time, I run the Google maps app in the phone, which reports precise location point. How can the Google maps app obtain the higher precise location information than my app does?
PS. I registered LocationListners for every location provides with '0' minTime and '0' minDistance. But my phone never reports any location changes in several 10 minutes. I think this behavior is acceptable because the phone just stayed in my desk for that duration. But this condition is same for the Google maps app. It reports the phone's location exactly still.
UPDATE. I tested my code in Galaxy S2. In this case, I requested 3 provides' getLastKnownLocation(GPS, NETWORK, PASSIVE). All the locations was null. And I registered LocationListeners for all the provides. It did not report anything. But in that time, the Google Map apps showed me precise location of the phone. Amazing!. Where does the Google Map apps get location information from?. Following is my test code.
LocationListener locationListenerNetwork = new LocationListener() {
public void onLocationChanged(Location location) {
Log.i("location","location chagned x:"+location.getLatitude()+" y:"+location.getLongitude()+" prov:"+location.getProvider());
Date d = new Date(location.getTime());
Log.i("location","date:"+d);
}
public void onProviderDisabled(String provider)
{
Log.i("location","disable:" +provider);
}
public void onProviderEnabled(String provider)
{
Log.i("location","Enable:" +provider);
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
Log.i("location","onStatusChanged:" +provider);
}
};
LocationListener locationListenerPassive = new LocationListener() {
public void onLocationChanged(Location location) {
Log.i("location","location chagned x:"+location.getLatitude()+" y:"+location.getLongitude()+" prov:"+location.getProvider());
Date d = new Date(location.getTime());
Log.i("location","date:"+d);
}
public void onProviderDisabled(String provider)
{
Log.i("location","disable:" +provider);
}
public void onProviderEnabled(String provider)
{
Log.i("location","Enable:" +provider);
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
Log.i("location","onStatusChanged:" +provider);
}
};
LocationListener locationListenerGps = new LocationListener() {
public void onLocationChanged(Location location) {
Log.i("location","location chagned x:"+location.getLatitude()+" y:"+location.getLongitude()+" prov:"+location.getProvider());
Date d = new Date(location.getTime());
Log.i("location","date:"+d);
}
public void onProviderDisabled(String provider)
{
Log.i("location","disable:" +provider);
}
public void onProviderEnabled(String provider)
{
Log.i("location","Enable:" +provider);
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
Log.i("location","onStatusChanged:" +provider);
}
};
void showDebug(String provider)
{
Location location = lm.getLastKnownLocation(provider);
if(location!=null)
{
Log.i("location","all location provider:"+provider+" x:"+location.getLatitude()+" y:"+
location.getLongitude()+" actually provider:"+location.getProvider()+" accuracy:"+location.getAccuracy()+" time:"+location.getTime());
Date d = new Date(location.getTime());
Log.i("location","date:"+d);
if(this.current==null)this.current=location;
else if(this.current!=null && isBetterLocation(location,this.current))this.current=location;
}
else Log.i("location","all location provider:"+provider);
}
void start()
{
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.removeUpdates(locationListenerNetwork);
lm.removeUpdates(locationListenerPassive);
lm.removeUpdates(locationListenerGps);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0, 0, locationListenerNetwork);
lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, locationListenerPassive);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
showDebug(LocationManager.NETWORK_PROVIDER);
showDebug(LocationManager.PASSIVE_PROVIDER);
showDebug(LocationManager.GPS_PROVIDER);
}