This is possibly off-topic for SO, if so I apologise (and gladly accept the flag for closure), but I'm having issues figuring out why when WIFI is on, but not connected to any access point (on my android device), it vastly improves the accuracy of network provider when using LocationManager
. Without it on, the general network location result is about 1 mile away from my current position. Also, most of the time the lat/lng values returned are different, so it's not even that it requested once and just cached the result in lastKnownLocation()
Obviously I'm using both GPS and Network providers to get a decent fix on end-user location (when either isn't available), and using the timestamp to figure out which is the latest.
I've searched google and have come up with various answers like: "It just does" and "Its magic" - Which are pretty useless to be honest. I don't want an in-depth description of the inner workings, just a slightly lower level than: "It just does", or "that's how it works".
requested code
// first get location from network provider //
if(isNetworkEnabled)
{
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_FOR_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,
this);
Logging.Debug("GPSTracker", "Network");
if(locationManager != null)
{
netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(netLocation != null)
{
latitude = netLocation.getLatitude();
longitude = netLocation.getLongitude();
speed = netLocation.getSpeed();
}
}
}
// if gps is enabled get lat/lng using that as well //
if(isGPSEnabled)
{
if(gpsLocation == null)
{
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_FOR_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,
this);
Logging.Debug("GPSTracker", "GPS Enabled");
if(locationManager != null)
{
gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(gpsLocation != null)
{
latitude = gpsLocation.getLatitude();
longitude = gpsLocation.getLongitude();
speed = gpsLocation.getSpeed();
}
}
}
}
Any insight is greatly appreciated. Thanks.